Semantic HTML Tags | HTML5 Semantic Elements Tutorial

Dave Gray
4 Jan 202224:37

Summary

TLDRIn this beginner's HTML tutorial, Dave guides viewers through enhancing their web pages with semantic HTML. He emphasizes the importance of a clear heading hierarchy, utilizing header, main, and footer elements, as well as semantic tags like article, section, nav, and aside. Dave also covers accessibility, using ARIA labels for navigation and introducing interactive elements like details and summary. The lesson concludes with validating and outlining the HTML structure for improved web page organization and assistive technology compatibility.

Takeaways

  • 🌟 Use semantic HTML to improve code organization and accessibility for screen readers and other assistive technologies.
  • 📚 Start with a clear hierarchy of headers: one main h1 per page, with h2 for subtopics, and h3 for subtopic subsections if needed.
  • 🔗 Add a nav element for grouping links that help navigate the page, and label it with aria-label for clarity.
  • 📝 Include a header element to wrap the page's main heading and navigation, maintaining the heading hierarchy.
  • 📊 Wrap main content in a main element, which should be unique per page to denote the primary content area.
  • 🔖 Use article elements for sections with a clear, standalone topic, instead of sections which are more generic.
  • 📌 Employ sections within articles for nested content, and use h3 for subheadings to maintain the heading hierarchy.
  • 📄 Utilize aside elements for complementary content that is less important than the main article content.
  • 🔍 Enhance content with details and summary elements for interactive content, like quizzes or additional information that can be expanded or collapsed.
  • 🎨 Use mark and time elements to add semantic meaning to highlighted text and durations, respectively.
  • ⚠️ Avoid using div and span elements in favor of semantic elements unless no semantic alternative is available.

Q & A

  • What are the main tools used in this HTML tutorial?

    -The main tools used in this tutorial are the Chrome web browser, Visual Studio Code editor, and the Live Server extension for Visual Studio Code.

  • How does the hierarchy of headers work in HTML?

    -In HTML, the hierarchy of headers starts with one H1 per page as the main title, followed by multiple H2 headers for subtopics, and then H3 headers for subtopics of subtopics. It's recommended not to go beyond three levels of headings.

  • What is the purpose of the 'nav' element in semantic HTML?

    -The 'nav' element in semantic HTML represents a section of the page that groups together links, typically for navigation to other pages or sections within the same site.

  • Why is using semantic HTML important for web accessibility?

    -Semantic HTML is important for web accessibility because it provides additional meaning to the content, making it easier for screen readers and other assistive technologies to interpret and navigate the webpage.

  • What does the 'header' element in HTML represent?

    -The 'header' element in HTML represents the introductory content for a section of the page, which typically includes the page's main heading and navigational links.

  • What is the 'main' element used for in an HTML document?

    -The 'main' element is used to wrap the primary content of the page, indicating that it contains the central topic or focus of the webpage.

  • How can you label navigation elements for assistive technology?

    -You can label navigation elements for assistive technology using the 'aria-label' attribute, which provides a descriptive name for the navigation area.

  • What is the difference between 'article' and 'section' elements in HTML?

    -The 'article' element represents a self-contained composition with a clear topic, while the 'section' element is used to group content that forms a section of a document, such as chapters, headers, or any other sectioning content.

  • How do you use the 'details' and 'summary' elements together?

    -The 'details' element is used to create an interactive widget that contains a 'summary' element. The 'summary' element represents the visible heading for the 'details' element, and clicking on it reveals or hides the additional content within the 'details' element.

  • What is the purpose of the 'time' element with a 'datetime' attribute?

    -The 'time' element with a 'datetime' attribute represents a specific period or date, and the 'datetime' attribute provides a machine-readable format of the date or time, enhancing the semantic meaning of the content for technologies that read the webpage.

  • Why should 'div' and 'span' elements be avoided when learning HTML?

    -Both 'div' and 'span' elements should be avoided when learning HTML because they do not convey semantic meaning by themselves. 'Div' is a block-level element equivalent to a section without semantic meaning, and 'span' is an inline element used for styling without adding value to the content. It's recommended to focus on using semantic elements when starting with HTML.

Outlines

00:00

📚 Introduction to Semantic HTML

The video begins with an introduction to a beginner's HTML tutorial series. The presenter, Dave, outlines the tools he will be using, including the Chrome web browser, Visual Studio Code editor, and the Live Server extension. He emphasizes the importance of document organization and semantic HTML, explaining how it improves code readability and navigation. Dave also discusses the hierarchy of headers, from H1 to H6, and their role in structuring content like an essay outline. The main focus of this segment is on adding semantics to the index.html page to enhance its structure and accessibility.

05:00

🛠️ Enhancing HTML with Semantic Elements

In this paragraph, Dave continues to improve the HTML code by adding semantic elements such as the 'nav' element for navigation links and 'hr' for horizontal rules, which signify topic changes. He also discusses the importance of the 'header' and 'footer' elements in defining the top and bottom sections of a page. Dave demonstrates how to use these elements to create a more structured and accessible webpage, including the use of ARIA labels for assistive technology. The summary highlights the process of enhancing the webpage's semantic structure and the role of various HTML5 elements in improving both user experience and accessibility.

10:01

📝 Refining Content with Appropriate Tags

This section focuses on refining the content of the webpage by using appropriate HTML tags. Dave explains the difference between 'article' and 'section' tags, emphasizing that 'article' represents a standalone topic, while 'section' is more generic. He demonstrates how to use 'article' tags for the HTML and vacation topics and introduces 'section' tags within these articles for subtopics. The paragraph also covers the use of 'aside' for complementary content and 'details' with 'summary' for additional information. The summary captures the essence of semantic tagging and the significance of maintaining a clear hierarchy in webpage content.

15:02

🚫 Avoiding Non-Semantic Elements

Dave discusses the importance of avoiding non-semantic elements like 'div' and 'span' in favor of semantic elements. He explains that 'div' stands for 'divider' and lacks semantic meaning, requiring additional effort to convey meaning to assistive technologies. Similarly, 'span' is an inline element with no inherent meaning. The paragraph emphasizes the benefits of using semantic elements for better code structure and accessibility. Dave also briefly touches on the use of HTML5 Outliner, a Chrome extension that helps visualize the structure of a webpage. The summary stresses the importance of semantic HTML for creating well-structured and accessible web content.

20:03

🔍 Validating and Outlining the Webpage

The final paragraph covers the process of validating and outlining the webpage. Dave uses the W3C Markup Validation Service to ensure there are no errors or warnings in the HTML code. He also introduces the HTML5 Outliner extension to visualize the webpage's structure, highlighting the importance of maintaining a proper heading hierarchy. The summary emphasizes the importance of validation and outlines the steps taken to review the webpage's structure, ensuring that the semantic elements are correctly used and that the page is accessible and well-organized.

Mindmap

Keywords

💡Semantic HTML

Semantic HTML refers to the use of HTML tags that provide meaning to the content they enclose. In the video, semantic elements like `<nav>`, `<header>`, `<footer>`, `<section>`, `<article>`, and `<aside>` are used to structure the webpage in a way that is easily understood by both humans and machines, such as screen readers. This enhances accessibility and SEO.

💡Heading Hierarchy

Heading hierarchy is the organization of headings (H1, H2, H3, etc.) in a document to represent the structure of the content. H1 is the main heading, and subsequent headings (H2, H3, etc.) represent subtopics or sections. Proper heading hierarchy is crucial for accessibility and SEO, as it helps users and search engines understand the document's structure.

💡Live Server Extension

The Live Server Extension is a plugin for Visual Studio Code that allows developers to view their web pages in real-time as they make changes. It automatically refreshes the browser window whenever a file is saved, providing a live preview of the webpage.

💡Visual Studio Code

Visual Studio Code, often abbreviated as VS Code, is a free, open-source code editor developed by Microsoft. It supports a wide range of programming languages and offers various features such as debugging, version control, and extensions, making it a popular choice among developers.

💡HTML5 Outliner

HTML5 Outliner is a Chrome extension that generates an outline of a webpage based on its semantic structure. It helps developers visualize the document's hierarchy and ensure that the heading levels are used correctly, which is essential for accessibility and search engine optimization.

💡Accessibility

Accessibility in web development refers to making web content usable by people with a wide range of abilities. This includes using semantic HTML to make content understandable for screen readers and ensuring that the website can be navigated and interacted with by users with disabilities.

💡W3C Validator

The W3C Validator is an online service provided by the World Wide Web Consortium (W3C) that checks HTML and XHTML documents for errors and warnings. It ensures that the markup is well-formed and adheres to web standards, which is important for cross-browser compatibility and maintaining web standards.

💡CSS

CSS (Cascading Style Sheets) is a style sheet language used for describing the presentation of a document written in HTML. It separates the presentation (layout, colors, fonts) from the content (text, images, data), allowing for more maintainable and flexible web design.

💡ARIA Labels

ARIA (Accessible Rich Internet Applications) labels are attributes that can be added to HTML elements to provide additional information about the role or function of the element to assistive technologies like screen readers. They enhance the accessibility of a webpage by making it easier for users with disabilities to understand the content.

💡HTML Elements

HTML elements are the building blocks of web content, consisting of tags that define the structure and content of a webpage. Each element has a specific purpose and meaning, and they are used to create headings, paragraphs, lists, links, images, and more.

💡Web Accessibility

Web accessibility is the practice of making websites usable by people with disabilities. This includes providing text alternatives for images, ensuring that websites can be navigated using keyboard commands, and making content perceivable and operable. Accessible websites are more inclusive and comply with standards like the Web Content Accessibility Guidelines (WCAG).

Highlights

Introduction to using the Chrome web browser, Visual Studio Code editor, and the Live Server extension for viewing web pages.

Explanation of the importance of document organization and the use of semantic HTML for improving code readability and accessibility.

Proper use of header hierarchy with H1, H2, and H3 tags to structure the page content effectively.

Inclusion of a navigation element (nav) for better user experience and ease of navigation within the web page.

Utilization of horizontal rules (hr) to signify topic changes and their semantic meaning in HTML.

The significance of semantic HTML in making web pages accessible to screen readers and assistive technology.

Use of section elements to define distinct sections within a page, enhancing the semantic structure.

Transition from sections to articles for content with a clear, standalone topic.

Explanation of the footer element's role in encapsulating page-end content, such as copyright information.

Introduction to the aside element as a semantic way to present complementary or sidebar content.

Use of the details and summary elements for creating interactive content, such as quizzes or FAQs.

Explanation of the mark element for highlighting text within a block of content.

Inclusion of time elements with datetime attributes to provide semantic meaning to time-related data.

Discussion on the avoidance of div and span elements in favor of semantic elements for better code structure and accessibility.

Validation of the HTML page using W3C's validator to ensure code quality and adherence to standards.

Use of the HTML5 Outliner extension to visualize the document's structure and hierarchy.

Transcripts

play00:00

[Music]

play00:04

hello and welcome hi i'm dave

play00:07

this tutorial is part of a beginner's

play00:09

html series i'll be using the chrome web

play00:12

browser the visual studio code editor

play00:14

and the live server extension for visual

play00:16

studio code to view the web page there

play00:19

are links to these tools starter code

play00:21

files and all resources in the

play00:23

description below documents need

play00:25

organization and our html files are no

play00:28

different html achieves document

play00:30

organization with semantics in this

play00:32

lesson we're going to improve our code

play00:34

with the semantic html layout let's get

play00:37

started i've got visual studio code here

play00:39

on the left with our index.html open and

play00:43

on the right

play00:44

i have got our index html page

play00:47

displaying and we're using the live

play00:49

server extension for visual studio code

play00:52

to display that page and you can see

play00:54

it's launched down here you can click to

play00:56

close or open the server you can search

play00:58

for that extension over here at the

play01:00

extensions icon if you do not have it

play01:03

again it's the live server extension

play01:06

okay so we're adding semantics to our

play01:09

index html page now we've already added

play01:12

some so let's highlight what we have

play01:15

done already as we've built this page

play01:17

out over the lessons the main thing that

play01:19

we have done correctly is add a

play01:22

hierarchy of headers you only want one

play01:24

h1 per page

play01:26

and this should be an outline much like

play01:29

you would have an outline for an essay

play01:31

or any type of paper topic you would

play01:34

write so this is your title for the

play01:36

whole page essentially

play01:38

and from there you can have multiple h2

play01:41

headers which is one level down in the

play01:43

hierarchy

play01:44

and they would define subtopics and then

play01:47

beneath that you could have h3 headers

play01:50

if there was a subtopic of a subtopic

play01:53

and so on and that continues to h6

play01:55

although you really don't want any more

play01:57

than about three

play01:58

levels of headings on a page so h1 h2 h3

play02:03

would be the ideal way to have a page

play02:06

laid out

play02:07

after that we need to consider some

play02:09

things about semantic html writing

play02:11

semantic html helps us quickly see or

play02:14

read the different sections in a web

play02:16

page and navigate to those sections now

play02:18

we've already added a nav element to our

play02:21

page

play02:22

and nav elements are semantic elements

play02:25

so this says we have a grouping of links

play02:28

here and we can see that on the page

play02:29

with learning html and planning a

play02:32

vacation we have a grouping of links

play02:34

here that will help us navigate to the

play02:35

rest of the page we also have an hr

play02:38

which stands for horizontal rule in the

play02:41

past i believe i might have said these

play02:43

didn't really have a semantic meaning

play02:45

but they do they're currently viewed

play02:48

as semantic elements and it means that

play02:51

there is a topic change so something is

play02:54

changing and of course we have a couple

play02:56

of topics on our page and we have

play02:58

horizontal rules between those in the

play03:00

future as we learn css we may want to

play03:03

remove the horizontal rules we see here

play03:06

that divide our navigation and our

play03:08

heading for the page and replace those

play03:11

with lines that we can create with css

play03:13

because we're not really separating

play03:15

topics here although it doesn't hurt to

play03:17

have these horizontal rules in place at

play03:19

this time and the main thing to convey

play03:21

about semantic html is the word semantic

play03:24

that means it provides meaning as the

play03:27

nav element says hey this is a

play03:29

navigation area or the h1 element says

play03:32

hey this is a heading we can also get

play03:34

that from other parts of the page we

play03:36

added section elements that say this is

play03:39

a new section so they provide additional

play03:42

meaning rather than just

play03:45

a generic

play03:46

divider and we will talk about what a

play03:49

generic divider is later as well now in

play03:51

addition semantic html makes our pages

play03:54

accessible to screen readers and other

play03:56

assistive technology and that is very

play03:58

important as we create pages now while

play04:01

we've added some semantic html already

play04:03

let's add the three big areas that most

play04:07

consider for pages the first is not a

play04:10

head section but a header for our page

play04:13

now we have a heading which is the title

play04:16

of the page but we can wrap this in a

play04:19

header element and there can be more

play04:22

than one header element per page however

play04:25

it needs to follow the heading hierarchy

play04:27

so imagine if we had

play04:29

a social media site now every post

play04:33

whether it would be a blog post or a

play04:35

post like facebook or instagram every

play04:38

post could have its own header and it

play04:40

might have a subtitle in that post as

play04:43

well

play04:44

but this is a header now for our full

play04:47

page so this would be

play04:49

at the top level of our page with the

play04:52

hierarchy here of h1 which is the

play04:54

heading for our page notice we've also

play04:56

included the navigation inside of our

play05:00

header and we can go ahead and remove

play05:03

this horizontal rule and i think it will

play05:05

be just fine we don't need the semantic

play05:07

meaning of a change topic there and i

play05:10

think it's going to look okay without

play05:11

the line as well so let's save this now

play05:14

and we can see live server updates our

play05:16

page immediately so we can see the

play05:18

change and really all we see visually is

play05:21

that our horizontal rule is removed

play05:23

however we have added some extra meaning

play05:26

to our html here now that this is the

play05:29

heading or the header section for our

play05:32

full page now the next element we want

play05:35

to add

play05:36

is the main element now there can only

play05:38

be one main element per page and by

play05:42

definition that would make sense you can

play05:44

only have one

play05:45

main area for content

play05:47

per page and so we'll start here and

play05:50

it's going to include our sections that

play05:52

we've created so i used ctrl x to cut

play05:55

the closing main element tag

play05:58

and i'll scroll down to where our

play06:00

second section ends before our area here

play06:04

at the end and i'll paste

play06:06

the closing main element and save and we

play06:09

can see visual studio code reformatted

play06:11

for us so now we've got the main

play06:14

element wrapping

play06:16

our two topic areas of vacation

play06:20

and of html so we've added a header and

play06:23

a main element now one other thing we

play06:25

can add for our page is a footer now

play06:29

just like the header there can be more

play06:31

than one footer per page and that might

play06:35

be a footer for a blog post or a footer

play06:37

for a social media post but this is the

play06:40

footer for our

play06:41

entire page in this example once again

play06:44

ctrl x to cut that closing tag and i'm

play06:47

going to wrap everything we have here at

play06:48

the end in the footer

play06:50

one other thing i want to add just

play06:52

because i didn't do it before we

play06:54

validated our page throughout the other

play06:56

lessons and it's not an error it's not a

play06:59

problem but i want to include this

play07:01

information here about the copyright i

play07:03

want to include that in a paragraph

play07:05

element so

play07:06

i'm going to make sure that's lowercase

play07:09

why am i getting a capital there we go

play07:12

and then i'm going to once again

play07:14

cut the closing tag and put it

play07:17

after the content and save it gets

play07:20

reformatted it really doesn't change the

play07:22

look i just wanted both inside that

play07:25

paragraph and that might help in the

play07:26

future when we want to format this area

play07:29

as well with css so now our document has

play07:32

been outlined into three major sections

play07:34

we have a footer a main area and a

play07:37

header and then inside the header we've

play07:40

already discussed we have a navigation

play07:43

element that is also

play07:45

semantic html our list is also semantic

play07:48

html we know right away that this is

play07:51

providing a list and this would be

play07:52

identified by assistive technology as

play07:54

well now there can be more than one nav

play07:57

element per page so we might have a nav

play08:01

area in the footer footers often have

play08:04

links to other areas

play08:06

of a website now we've only got a couple

play08:08

of links in our footer and one goes back

play08:10

to the top and the other does go to our

play08:12

about page however it's not a grouping

play08:15

of links where we would organize if we

play08:17

had several other things here i might

play08:19

consider a nav and if you do have more

play08:22

than one nav element per page it's

play08:24

important that they are labeled so

play08:27

assistive technology knows which nav is

play08:31

which and here we can do that with an

play08:34

attribute called aria dash label

play08:37

and then we can set it equal to

play08:39

something that clearly says what it is

play08:41

like primary

play08:43

navigation and now we have labeled

play08:46

rnav as the primary navigation area if

play08:49

you did include a heading in the nav

play08:52

element which is not required

play08:54

but if you did

play08:55

you could link to that so you could have

play08:58

an h2 here

play09:00

and then in the h2 we might put

play09:02

primary

play09:05

navigation

play09:06

if i can spell it there we go and now

play09:08

let's give this an id

play09:12

and here we'll give the id

play09:14

the same value primary

play09:18

navigation and then here instead of aria

play09:22

we would say aria

play09:25

labeled by is the correct attribute here

play09:28

now we're looking at

play09:30

our primary navigation value

play09:33

and it's saying hey it's labeled by this

play09:35

value that's in the h2 so you can link

play09:38

these together with an aria labeled by

play09:41

pointing back to the id

play09:43

of a heading however since we're not

play09:45

going to have an h2 in our nav i'll go

play09:49

ahead and remove that

play09:50

and you can just choose the aria

play09:53

label attribute and set that equal to

play09:55

primary navigation which is equally

play09:58

accessible to screen readers and other

play10:00

technologies okay let's scroll down into

play10:03

this main area previously we broke our

play10:06

topics html and vacation into sections

play10:11

which are semantic html tags however

play10:14

there is a more appropriate tag now that

play10:17

we kind of have an idea of how our page

play10:19

is laid out because these are

play10:22

areas that could be

play10:23

on their own maybe they would each have

play10:25

their own page but much like a social

play10:28

media post or a blog post some type of

play10:32

article you might think there is an

play10:34

article element so i have highlighted

play10:37

this section and i'm going to type

play10:38

article instead and i believe we'll find

play10:41

that vs code changes our closing tag

play10:44

immediately yes and it was already

play10:45

changed to article

play10:47

so

play10:47

instead of a section let's call this an

play10:50

article because it clearly has its own

play10:52

topic and now let's do the same for our

play10:55

other section based on vacation so we

play10:57

can highlight it

play10:59

change it to article and we'll verify

play11:02

that the closing tag is also article

play11:05

and yes it is right here so now we have

play11:08

two articles instead of sections now

play11:10

there is sometimes a debate about which

play11:13

should be used and it's really not

play11:15

clearly defined if article or section is

play11:18

the proper choice they would both pass a

play11:21

validator check so really the way i look

play11:24

at it is an article has a clear topic

play11:27

where a section is more generic you

play11:29

might use a section

play11:31

just to actually create a little section

play11:33

in your code whereas an article has a

play11:36

clear topic that the area is about so

play11:39

now inside of the article we could

play11:41

create other articles but now i want to

play11:44

go ahead and add a couple of sections

play11:47

inside of our html article so as our

play11:50

article begins we've got the heading

play11:52

which is h2 and it says i'm ready to

play11:54

learn html and then we have a paragraph

play11:56

saying this is my first web page that's

play11:58

fine let's go ahead and add the section

play12:01

after that point

play12:03

and now once again i'll press tab to get

play12:06

both the opening and closing tags i'm

play12:08

going to highlight the closing tag ctrl

play12:10

x to copy it i'm going to bring it down

play12:13

here to just underneath the figure and

play12:16

that's where we'll end this first

play12:17

section i also want to go ahead and add

play12:20

a subheading here which is an h3 and

play12:23

i'll just make this html5 as that's what

play12:25

the section is about

play12:27

and now our section has the subheading

play12:31

html5 it has the html5 logo and it has

play12:35

our figure that has our code sample of

play12:37

html5

play12:38

that all seems related now let's add

play12:41

another section and this is the my daily

play12:44

schedule section so

play12:46

lowercase again is what i prefer

play12:49

and so we'll have section and the

play12:51

closing section tag i will cut that and

play12:54

i'll put it here at the end of the list

play12:56

before the closing article tag so now we

play12:58

have two clear sections inside of our

play13:01

article and they both have headings that

play13:04

are h3 so we're at the third tier of the

play13:06

heading with the h1 being the heading

play13:09

for the overall page the h2 being the

play13:11

heading for the article and then the h3s

play13:14

being the headings for the nested

play13:16

sections within the article so we're

play13:18

keeping our hierarchy in place

play13:20

underneath the list we can add another

play13:23

element and just a little more content

play13:25

let's call this an aside this is a

play13:28

semantic element and if you think about

play13:30

how a web page is laid out often times

play13:33

you think of an aside as the sidebar to

play13:35

the page but it could also just be

play13:38

another section of complementary text

play13:41

that is not

play13:42

as important as what's in the main

play13:45

section or article that you are putting

play13:47

it inside of and that's what we'll do

play13:49

here and then i want to use some other

play13:52

semantic elements just to demonstrate

play13:54

how they work so now i'm going to add a

play13:57

detailed semantic element

play13:59

and inside a details element you want to

play14:02

add a summary element now the summary if

play14:05

this was a product we might just put

play14:07

warranty information in here as the

play14:09

summary here i'm going to put something

play14:12

that's more like a question and it will

play14:14

display how the details and summary work

play14:17

so i'm going to say

play14:20

guess the number

play14:21

of hours

play14:24

i code

play14:25

per day as our summary now underneath we

play14:28

can put the answer to this question and

play14:31

now i'm going to put

play14:33

i start at

play14:35

8am and i write

play14:39

code for

play14:40

let's say three hours

play14:44

every morning

play14:46

and we can save that

play14:49

i'll scroll up so we have it up here

play14:50

towards the middle of our page

play14:52

and now let's scroll up here and let's

play14:55

look at what we have on the page because

play14:57

the rest of our semantic changes really

play14:59

didn't change the appearance here

play15:02

but this where we added this new content

play15:05

notice we're not seeing this paragraph

play15:08

at this point we just see guess the

play15:09

number of hours i code per day but it

play15:11

has this little arrow next to it if we

play15:13

click on this

play15:16

then we see the answer

play15:18

so that's a nice little addition that

play15:21

this html element adds and again these

play15:24

are all semantic elements so the aside

play15:27

has some meaning that it's complementary

play15:29

text it's not as important as what's in

play15:32

the rest of the article

play15:34

the details and the summary work

play15:36

together so

play15:38

this could once again provide details

play15:40

about a product say warranty information

play15:42

something else a return policy whatever

play15:45

but you could also use it kind of as a

play15:47

quiz here where you have a question and

play15:50

an answer let's go ahead and add just a

play15:52

couple of more semantic elements to this

play15:54

one is what we can do with a highlighter

play15:56

just like you might use a highlighter on

play15:58

a piece of paper there is an element

play16:00

called mark so i'm going to mark what i

play16:03

want to highlight here in the text

play16:06

and by including it in the text you know

play16:08

it's an inline element and not a block

play16:11

element

play16:12

so now if i save that we have

play16:14

highlighted

play16:15

number of hours now inside the answer

play16:18

we're looking at some time here we have

play16:21

8 am and we also have a duration of 3

play16:24

hours we can add some meaning to that in

play16:27

the text as well

play16:29

and we can provide a time element then

play16:31

we need a date

play16:34

time attribute

play16:35

and for the date time attribute value i

play16:38

want to put in the actual hours it

play16:40

accepts several values so this would be

play16:43

0 800 on a 24 hour clock

play16:46

and now let's put the closing time

play16:48

element after the 8 am here

play16:51

and notice if i save this right now

play16:54

and show this it does not change what 8

play16:57

am looks like at all but once again it

play16:59

provides meaning in our html for

play17:02

technologies that are reading it

play17:04

especially those assistive technologies

play17:06

but it could also provide some meaning

play17:08

for the browser itself now also it says

play17:11

as i write code for three hours we can

play17:14

provide a time element for the duration

play17:16

too so we have time once again with the

play17:19

date time attribute

play17:20

and now we'll put in a different value

play17:23

because there is a value for duration

play17:26

i'm going to put this closing

play17:28

tag at the end of the three hours now

play17:30

let's look at the value for duration we

play17:32

would put in pt3h

play17:35

and remember there is a link in all of

play17:38

the html resources that i link to in the

play17:41

description there is a link that shows

play17:43

all of the html elements so you can look

play17:46

up for example the time element on the

play17:48

mozilla developer network that's the mdn

play17:51

site and you can look at all the values

play17:53

that could be accepted for the date time

play17:56

attribute okay let's save this and move

play17:58

down to our vacation area where we also

play18:01

want to add two sections i think these

play18:04

are clearly defined already where we

play18:06

have subheadings for places i'd like to

play18:08

visit and really we have a subheading

play18:10

for places i don't want to visit i

play18:12

believe so here let's go ahead and add a

play18:15

section again lowercase

play18:19

and i'll take that closing section tag

play18:21

highlight it ctrl x to cut i'll scroll

play18:25

down here

play18:26

and we'll add that before the next

play18:29

subheading so

play18:31

there we go and save that and of course

play18:34

it reformats again

play18:36

now i'll add a section element

play18:39

and put the closing after we finish our

play18:42

places i want to avoid section

play18:45

and that would be at the end of our

play18:46

description list

play18:48

and we can save that now we've got two

play18:50

sections inside of this article as well

play18:53

and really once again it doesn't change

play18:55

the look but it does change how the

play18:58

browser interprets and it definitely

play19:01

adds a benefit for assistive technology

play19:04

now before we look at our document

play19:05

outline with these changes i want to

play19:07

quickly discuss and i'll just do it here

play19:09

by this comment where it says add more

play19:11

places two different elements that you

play19:13

want to avoid as you're learning html

play19:16

and then later on

play19:18

you can use them as we possibly get into

play19:21

them with css but there is a div in an

play19:24

older html code you will see divs

play19:27

everywhere sometimes you still do

play19:29

when those people that have been using

play19:31

divs are used to still riding them and

play19:33

they just continue what they've been

play19:35

doing in the past however there is no

play19:38

semantic meaning to a div think of a div

play19:41

much like a section without the semantic

play19:44

meaning it just stands for divider and

play19:48

really you can put them anywhere but if

play19:50

you do

play19:51

you really have to do a lot of work to

play19:53

get them to convey meaning you have to

play19:55

add additional attributes that help

play19:58

assistive technology interpret these

play20:01

elements because they have no meaning as

play20:03

is they are block elements so

play20:06

a very similar element that is an inline

play20:09

element if we just wanted to wrap a word

play20:11

or two in a paragraph in an element

play20:15

is span we'll definitely use some spans

play20:18

as we learn css however once again they

play20:21

have no meaning whatsoever by themselves

play20:25

they don't change or add any value to

play20:28

your code and we would use them possibly

play20:31

to apply some css styling to some words

play20:34

that we would highlight around span so

play20:37

we really want to avoid both of these

play20:39

elements as you learn html really work

play20:42

on using semantic elements and then

play20:46

when you understand what semantic

play20:48

elements are and how to use them and

play20:50

then occasionally when just no semantic

play20:53

element is the correct choice

play20:56

that is the time that we actually should

play20:58

use divs and spans so i'm going to

play21:00

delete those for now

play21:02

and save our document and now i'll just

play21:04

scroll our code up to the very top and

play21:07

i'm going to do the same for our page

play21:10

over here on the right

play21:11

now what i want to bring your attention

play21:13

to i'm going to maximize the browser

play21:16

and we're going to go to the chrome web

play21:18

store and look at an extension we can

play21:21

add and that extension is html5

play21:24

outliner so search for that

play21:27

you'll find html5 outliner you can click

play21:30

on that and i've got it installed

play21:32

already so

play21:33

mine says remove from chrome yours would

play21:35

probably say install here and it will

play21:38

look at our semantic elements and make

play21:40

an outline of our page so let's check

play21:43

that out okay i'm going to bring our

play21:45

page back down to the size we had it

play21:49

down here to the bottom now once you've

play21:51

got that extension installed you may

play21:52

have to restart your version of chrome

play21:55

to get it to work but here we go click

play21:57

on html5 outliner and look we have got

play22:00

an outline of our current page so we've

play22:03

got our heading hierarchy correct with

play22:06

my goals for the year an untitled nav

play22:09

that's okay we didn't put a heading in

play22:11

there like i said we could have put an

play22:13

h2 it's just saying we didn't have one

play22:15

but a nav doesn't require one but

play22:18

remember if you do have more than one

play22:20

nav element per page then you do need to

play22:23

at least appropriately label that for

play22:25

assistive technology okay now we've got

play22:28

another section this is our article i'm

play22:30

ready to learn html and that's our h2

play22:33

heading

play22:34

inside the article remember we have two

play22:36

sections we have the html5 and my daily

play22:39

schedule and then we have an aside and

play22:42

this aside was inside the second section

play22:46

it's also untitled which is okay and a

play22:48

side does not have to have a heading

play22:52

but it just notes that as it's untitled

play22:54

here if you added a heading inside of

play22:57

the aside say an h4 then it would of

play22:59

course appear there

play23:01

now we've got our other section this our

play23:03

other article actually this i am also

play23:06

planning a vacation that was an h2

play23:08

and then these are h3 headings so you

play23:11

can see how important the headings are

play23:13

the heading hierarchy if you don't get

play23:15

any other semantics correct in your page

play23:18

that's the one thing to really

play23:20

understand is the heading hierarchy of a

play23:22

page but all of these other semantic

play23:24

elements definitely help outline your

play23:27

page and add meaning avoiding these is

play23:30

the biggest mistake you can possibly

play23:32

make as you are constructing an html

play23:35

page okay now that we've looked at our

play23:37

outline let's once again validate our

play23:39

page i'll pull this over just so we see

play23:42

a little bit better i'll click file

play23:44

upload we're at validator.w3.org

play23:48

and i'm going to click choose file i

play23:50

have to make sure i'm in the right

play23:52

lesson

play23:53

folder i am not so i need to go into

play23:56

html course

play23:58

lesson 7

play24:00

index.html just make sure you upload the

play24:03

index.html you were working on for this

play24:05

lesson

play24:06

click check and we'll see if we have any

play24:08

problems if you have a problem it will

play24:10

show here it should tell you what line

play24:12

and what the problem is but we're good

play24:14

to go document checking completed no

play24:16

errors or warnings to show remember to

play24:19

keep striving for progress over

play24:21

perfection and a little progress every

play24:23

day will go a very long way

play24:25

please give this video a like if it's

play24:27

helped you and thank you for watching

play24:29

and subscribing you're helping my

play24:31

channel grow

play24:32

have a great day and let's write more

play24:34

code together very soon

Rate This

5.0 / 5 (0 votes)

Ähnliche Tags
HTML TutorialWeb AccessibilitySemantic ElementsWeb DevelopmentVisual Studio CodeLive Server ExtensionHeading HierarchyWeb NavigationCSS FundamentalsWebpage Organization
Benötigen Sie eine Zusammenfassung auf Englisch?