Jump to content

Are HTML attributes required if using CSS?


L.Adlon

Recommended Posts

Hi. If, for example, I have an image tag, and I have a CSS style class defined for all images, are the standard <img> attributes (ex. width, border, etc), aside from the src attribute required if the class definition sets them?

 

Do you include them anyway, just as a backup?

 

 

As an example, if I define this:

 

img.gallery {width:300px; height:400px; border-style:solid; border-width: 2px; border-color:black; .... }

 

Would my image tags only need to be something like this:

 

<img src="images/photo1.jpg" alt="First photo" class="gallery" />

 

...or, are the attributes like width, height, border, etc still required?

 

Is putting the <img> attributes that are also defined in the class redundant, or required?

Edited by L.Adlon
Link to comment
Share on other sites

Presentational attributes are not required, and best if they're not used. Presentional attributes are those that determine what an element looks like and how it's formatted.

Link to comment
Share on other sites

Hi, Ingolme.

 

Sorry, help me out here, as I'm not terribly well-versed in the whole coding thing.

 

I get what you mean by presentational, at least at a conceptual level... but I just want to be sure of the specifics.

 

Are you saying that an image tag could simply be <img src="images/photo1.jpg" alt="First photo" class="gallery" />, as long as the other attributes that would normally be included in the html tag are addressed in the class definition ('gallery') in the style sheet? No harm in keeping them out of the <img> tag?

 

I would only tend to keep them in there (even if redundant) in fear that there may not be 100% support for the CSS, and the attributes in the image would then serve as a backup for it to fall on. Is support for the CSS 100% now (for the standard <img> attribues)?

Link to comment
Share on other sites

There's been support for CSS for 15 years, no need to worry about that. Normally the <img> tag just has src and alt attributes. class and id can be used for CSS styling or Javascript manipulation.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...