CSS adding styling class to html

Hi all

Simple question, do people think it’s a good idea to add stylying class in the html.

I can add a class like font-bold in the html and then in the css have

	font-weight: bold;

Very simple but I’m thinking it’s counter productive as if i need to change it I have to search through and chnage the class names in the html.

This approach destroys the main idea of CSS classes.
There is no difference between class="font-bold" and style="font-weight: bold".
So there is no point to use class instead of inline style.

Why not use strong ?

I don’t think you should have classes that describe what the styling is about. E.g. .red-font-color{color:red;}

Sorry, bold was a bad example it could be rd as the class name and then color: red; as the class.

I was thinking more about using class names in the html

Good point megazold it is like using an inline style

And inline styles are bad. The main idea of CSS is allow us to separate logic (tags) from view (styles).
That means right usage of CSS assumes you’re giving classes to elements depending on they logical purpose.

For example:

<div class="product">
    <div class="title">My product</div>
    <div class="snippet">Buy it, please!</div>
    <div class="price">$100</div>

You can still style each element individually but you also keep your HTML semantic.

You may want an element to look red now, but later you may change your mind, and you’ll feel silly if you end up with this:

.red {color: blue;}

That’s why Ryan said this:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.