-3

I just got a html template with sections and a few things are not clear about them.

The file contains a section look like this:

<section id="section-name" class="row"> 

</section>

As I already found simple <section> </section> tags, I'm confused about a few things. Mainly, what does the section id's? Are they referring to CSS rules or they can be used without any connection with the CSS? So far I couldn't find anything in my CSS file related to the used section names so I assume the id's are named based on practical reasons that helps to structure the code.

Am I right that section id's don't have any connections with CSS? Or they can refer to CSS options but they can also work without any CSS related connection?

rihekopo
  • 3,241
  • 4
  • 34
  • 63
  • IDs don't need to be tied to CSS. Then can also be used in JavaScript or not used it either. – j08691 Aug 28 '17 at 20:01
  • 1
    ID is not specific to section. [This post](https://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html) has a lot of good information. – big nol Aug 28 '17 at 20:02
  • 1
    The `id` attribute specifies a unique identifier for an HTML element (the value must be unique within the HTML document). It is most used to point to a style in a style sheet, and by JavaScript (via the HTML DOM) to manipulate the element with the specific ID. – Alessio Cantarella Aug 28 '17 at 20:02
  • 1
    id with # or . with classname as we use for div's are the better ways of applying css properties with html.But I don't see anything much different by using a section tag.Section is not a good option used for wrapping.Read this once http://html5doctor.com/avoiding-common-html5-mistakes/ – Chetan_Vasudevan Aug 28 '17 at 20:05
  • [Eleven uses for Id in HTML](https://stackoverflow.com/questions/13001236/why-should-one-add-id-to-their-html-tags#13001519) – Alohci Aug 28 '17 at 21:08

3 Answers3

3

The id attribute on a section does exactly the same as it does on every other element.

  • You can link to it with a fragment identifier on the end of a URL
  • You can target it with CSS
  • You can target it with a programming language (e.g. client side JavaScript).

There is nothing unique to sections about how the id attribute is handled.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

It's the same as an ID on any other tag. You don't have to use it in CSS, but you can.

jhpratt
  • 6,841
  • 16
  • 40
  • 50
0

You can use sections in css like this: css:

section
{
color:red;
}

or

section#section-name
{
color:red;
}   

or

section.row
{
color:red;
}

or

section#section-name.row
{
color:red;
}