Luis Alvarado
Luis Alvarado

Reputation: 9406

Reasons to use an inline style?

What would be some good reasons to have to use inline style as oppose to an external css file or css code in the header?

Upvotes: 3

Views: 1806

Answers (4)

Diego
Diego

Reputation: 18379

Not all styles can be reused; some will be used by a single element in the HTML, so having a class for that may be an overkill and even increase the overall size of the file.

Using inline style can actually make HTML more readable and maintainable when the style can't be reused for other elements (tags).

Upvotes: 4

No Results Found
No Results Found

Reputation: 102874

The only reason I can think of is to make the HTML less readable and the CSS less maintainable. Not all styles can be reused; some will be used by a single element in the HTML, and having a class for that may seem like overkill and can slightly increase the overall size of the file - but having two different places where you have to edit the CSS makes things as a whole harder to maintain. This difficulty increases exponentially as you add more and more inline styles.

Moreover, while making changes, finding and navigating to the right HTML file to modify the inline CSS when you make a change to something else in your stylesheet can be a hassle and increases the effort of applying those changes. That's the definition of poor maintainability.

Upvotes: 0

Nilpo
Nilpo

Reputation: 4816

You should always try to find a way to avoid inline styles. They are often indicative of poor planning or lazy programming. That being said, they are available. Don't beat yourself up for using the tools that are available to you if a specific need arises.

Upvotes: 0

Matthew
Matthew

Reputation: 25793

One good reason to use inline styles is if you're using it for HTML emails. For every other opportunity, I think it would be best to use external styles with meaningful classes/ids and inheritance.

Upvotes: 6

Related Questions