Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Is inline CSS ever acceptable?

Featured Replies

Is it?

 

I only ask because in my most recent website I have used an inline style on an image which I knew wasn't going to be repeated anywhere, and it just seemed a lot easier to add a quick inline style rather than select it in a separate CSS file. This is the first time I have done this, and I feel like I shouldn't have done because it tends to be frowned upon - even though it seemed like the simplest solution. What do people think?

 

Thanks

I try not to use inline as much as possible...the main times I do use inline styles are when I have content being generated by PHP & need to style it based on the nature of the dynamic content.

 

Even if you think that an inline style may not need to be edited or restyled....you can never predict what will happen in the future - mixing inline styles where the rest of the site is external can be confusing if someone else needs to edit code...or even for you if you come back to it a year or more later.

 

Is it really less effort to code an inline style than an external one?

Is it?

 

I only ask because in my most recent website I have used an inline style on an image which I knew wasn't going to be repeated anywhere, and it just seemed a lot easier to add a quick inline style rather than select it in a separate CSS file. This is the first time I have done this, and I feel like I shouldn't have done because it tends to be frowned upon - even though it seemed like the simplest solution. What do people think?

 

Thanks

 

The only time I'd really use inline styles personally would be if you were dynamically calculating some style attribute on server-side. For example a quick way to get vertical centering on images of variable height could be :

 

<div style="padding-top: <?php print $div_height - getimagesize($image_url)[1] ;?>px;">

 

Doing it for quick fixes and things isn't a massive sin, but the more css you have sprayed out across your html the harder to maintain your code becomes.

 

Hope this helps,

 

Explosive Designs

Website Design by Explosive Designs

+1 James Riley - only use inline if you can't solve the problem in any other way, which will usually only rear it's head off the back of a dynamic script. This is more commonly a result of Javascript than server side scripting, but not exclusively.

 

Hacking something in because it's easier is the road to ruin...if you have time, do it right.

I only use it when I have to when using jQuery (JavaScript). Even then I make sure the site works just as well without and follows graceful degradation.

On clients sites I always do it properly but when messing around on my own sites often use inline to sort out how I want something to look and then transfer it into the style sheet but have to admit I can be a bit lazy or short of time on my own sites so sometimes I forget to move it over to the style sheet.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.