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.

Tag Weight Question

Featured Replies

When you have a form you can style the input tag. If the input tag as an idea ID the ID has more "weight" or specificity then input, correct ?

 

No ID

 

<input type="text" name="fname">
 

With ID

 

<input type="text" name="fname" id="newname">
 

 

id = identity

 

This is the reference by which your css will be attached to the element by the users browser.

 

The css would look something like -

#newname {
    display: block;
    color: #334;
}

This codeacademy tutorial will explain this properly for you.

As an element the input tag is of importance, you cannot enter data into a form without it (Except for textarea etc). ID is a means of targeting individual elements with css and scripts. They both have equal weight in that context as both are equally important if you want to produce a means on getting user input that will look the way you want it on screen, AND do things the way you want the input field to do them.

 

A tougher question though is which has more weight, css class, or id?

 

That I cannot answer ;)

For styles, I would use classes. That being said, you may use IDs for very specific rules/ names if you absolutely must - though it is very bad practise to apply the same ID to multiple elements in the same document. They should be exclusive.

ID is unique, class is reusable. In the instance of a form it's best practice to use labels, this is where the ID is used so in your case it would be.

 <label for="name">Enter your name:</label> <input type="text" name="fname" id="name"> 

 

This helps users to identify which input each label belongs to and since an ID must be unique there can be only one input this label belongs to.

 

As for 'weight' it's a loose term. As far as I'm aware ID and class can both carry semantic meaning with search engines and you can use a class as a way to define information as by wrapping something in a class or ID you're also saying 'this information could have some additional meaning' for example a postcode on it's own could be LU1 6RN but using class like this <span class="postcode">LU1 6RN</span> even if there is no style for the class the search engines can often pick up on this, just like <span itemprop="postalCode">LU1 6RN</span>.

in terms of specificity from lowest to highest it goes:

 

Element > class > ID - This means an ID will always carry more weight than a class or element selector.

 

Daisychaining elements, classes or ids like this: .classname1 .classname2 will double the specificity, but an ID has such a high specificity you would need a super long chain of class selectors to gain a greater weight.

 

Because ID's have such high specificity they should be avoided for styling purposes. Classes are also preferable because they are reuseable which will allow you to write much dryer code.

 

 

Ït should be noted as well that the order of code will also dictate specificity, code that comes later will have a higher specificty for the same selector:

 

.item {

color: red;

}

 

.item {

color: blue;

}

 

the second rule overruling the first.

Edited by rbrtsmith

ID is unique, class is reusable. In the instance of a form it's best practice to use labels, this is where the ID is used so in your case it would be.

 <label for="name">Enter your name:</label> <input type="text" name="fname" id="name"> 

 

This helps users to identify which input each label belongs to and since an ID must be unique there can be only one input this label belongs to.

 

As for 'weight' it's a loose term. As far as I'm aware ID and class can both carry semantic meaning with search engines and you can use a class as a way to define information as by wrapping something in a class or ID you're also saying 'this information could have some additional meaning' for example a postcode on it's own could be LU1 6RN but using class like this <span class="postcode">LU1 6RN</span> even if there is no style for the class the search engines can often pick up on this, just like <span itemprop="postalCode">LU1 6RN</span>.

So if I was to use the <span class="aClass"> technique to imply importance or significance to bots will that help SEO? or will it have a cost in the long run for, as Google calls it, 'playing' the search engine?

I'm about 99% Certain that classnames have absolutley no bearing on seo and also have no sementical meaning. The only reason you want to give good classnames is the same reason you give variables a meaningful name- To make the code more readable to humans.

I'm about 99% Certain that classnames have absolutley no bearing on seo and also have no sementical meaning. The only reason you want to give good classnames is the same reason you give variables a meaningful name- To make the code more readable to humans.

Unless you use microformats which uses classes to apply semantics to names, locations etc.

 

Example:

<a class="h-card" href="http://waterpigs.co.uk">Barnaby Walters</a> 

Edited by Nillervision

So if I was to use the <span class="aClass"> technique to imply importance or significance to bots will that help SEO? or will it have a cost in the long run for, as Google calls it, 'playing' the search engine?

 

I'm about 99% Certain that classnames have absolutley no bearing on seo and also have no sementical meaning. The only reason you want to give good classnames is the same reason you give variables a meaningful name- To make the code more readable to humans.

 

There is a direct relation to span indicating importance or it has a unique meaning, it's an inline just like <b> and <i>. The snippets often seen in search results are because the site uses identifiers e.g. <li>Name <span>John</span></li> identifies something special about John. In addition there is the wrapper <div> on 99% of listing sites; and they will often use either a class like class="pod". Now if you see a site with data underneath it's either caused by microformats or the search engine has determined a pattern and extracted what data it can; both can result in the same outcome though microformats have a much more precise approach. If in addition to the span the class was always class="telephone" and the span always contained a number then it should guess it's a phone number. Be it a loose microformat just like only using html 5 <section> it's still a primitive format of some description.

 

As for helping seo, it depends what you consider 'SEO'. In my mind helping a search engine understand the context of your content should focus your serps in the right direction, clarifying if you are talking about a product or actually selling a product will help the search engines put you in front of the right users. Microformats will be huge as I was saying last year but sadly got overlooked when people saw they could have a review count and a picture of their ugly mug next to it and took it no further.

I never said that dom elements have no meaning. Of course they do. but classnames do not. There are various articles around that state that ID''s and classnames have no bearing whatsoever on SEO - aside from microformats which to my understanding is not going to be of great importance if the document is well structured?

Edited by rbrtsmith

Do any of you guys use micro formatting? I'd be interested to see if it's something worth using in future projects.

I don't use it enough I've only recently learnt about it but I believe it can be quite efficient. But you should probably use Microdata (which is the HTML5 equivalent to microformats) it uses unique formatting attributes rather than class and rel attributes. Google webmaster tools has a tool to help you add microdata/formats https://www.google.com/webmasters/markup-helper/

andy9l from this forum was kind enough to explain the google tool to me in this post

Edited by Nillervision

When I have been studying other peoples code I thought these extra classes where simply a case of the devs using good coding practices and labelling things clearly for others to understand what was going on in their output. Now I see there is a lot more to this than meets the eye, but I am guessing that it was a case of good practice being picked up on by the search engines and parsers in browsers.

 

Being a simple amateur that likes learning all things web I'd be very interested to know if there are any good tutorial type blogs ( like the 'microformats2' blog that Nillervision quoted ) that would demonstrate how to make best use of both microformats and microdata techniques in the same document for maximum effect.

I've quite a bit of experience with schema microdata but as an example from a 'big' ish name using it is Thomson Local with this microdata.

 

I never said that dom elements have no meaning. Of course they do. but classnames do not. There are various articles around that state that ID''s and classnames have no bearing whatsoever on SEO - aside from microformats which to my understanding is not going to be of great importance if the document is well structured?

 

Not saying 100% the word will carry 'SEO' weight but if for example the same class is applied to the same elements always in the same place then this is an indicator of pattern. Again it's back to what is considered SEO - if you're looking for 'keywords' then no it won't help.

 

As for articles, it's down to the authors and what the current 'trend' is ... I've spent over a year experimenting with microdata, pushing it further than most with no help from any article as there was nothing other than Schema.org as a guide for deeper semantic meaning.

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.