Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Working with figure and figcaption

From: HTML5: Structure, Syntax, and Semantics

Video: Working with figure and figcaption

In addition to the structural and sectional content that we've been using, HTML5 introduces a number of new elements and redefines some of the older ones, that allow us to create richer semantic documents when grouping content. In this chapter, we're going to explore some of those elements, and we're going to start right here with a figure and the figcaption element. So obviously, I have the author-view HTML5 spec open, and I've navigated here to the figure element. So again it is a sectioning root, meaning anything inside of it won't show up in the document outline, so that's one thing that we already know about the figure element.

Working with figure and figcaption

In addition to the structural and sectional content that we've been using, HTML5 introduces a number of new elements and redefines some of the older ones, that allow us to create richer semantic documents when grouping content. In this chapter, we're going to explore some of those elements, and we're going to start right here with a figure and the figcaption element. So obviously, I have the author-view HTML5 spec open, and I've navigated here to the figure element. So again it is a sectioning root, meaning anything inside of it won't show up in the document outline, so that's one thing that we already know about the figure element.

And then in terms of the content model, what can we place inside of it, it can have a single figcaption, which we'll talk about in just a moment, followed by a flow content. Or we can have a flow content followed by a figcaption element. So figure caption can show up at the top or at the bottom of it, and we're going to talk more about what the figure caption is in just a moment. So essentially, if we look at the definition, the figure element represents some flow content, and that could be almost anything, but typically it's images or video or something that is illustrative of the content. As it mentions in the spec, the element can be used to annotate illustrations, diagrams, photos, code listings that are referred to for the main content of the document but could sit independently of that content if you wanted it to.

Now figure caption, well that is the child of the figure element, and it's optional. You don't have to have one, but if there is one, it represents the caption of the figure element's contents. So it's just a way of captioning, if you will, so you're sort of identifying what that content is. So we've got a couple of examples here. I don't want to spend too much time on these, but I just want to get a quick look at them. So you can see some of the ways figure can be used, and the first instance is being used to basically illustrate a code snippet. So we have some preformatted code inside of that, and there is our figure with a figure caption.

Here figure is being used to mark up a photograph, so images are quite common inside of figures. Well, here they have an image inside of a blockquote instead of a figure and then later on down they have an image that's inside of a figure. So, a lot of times it has to do with what's in the image and what the image is illustrating as to whether it belongs inside a figure element or not. They have also got video inside a figure element. So I think you're starting to get the point here. Here there is a little bit of a text of a poem. Really anything can go inside the figure element. It just has to be illustrative of the content that it's referencing.

Okay, so now that we have a handle on what the figure element is and what it can do for us, let's go back to our trails page and use figure element to help us add a little bit more meaning to our own code. Okay, so we have our trails page open, and this is in the 05_01 folder, and you're going to notice some changes right off the bat. For one, we now have a link to an external CSS style sheet, so since we're getting sort of into the more complex nature of our page and grouping some of the interior content, when we preview this, we want to see what this is going to look like relative to the finished page, so some of our styles are now attached--not all of them, we're going to be needing to do some of the styles, but most of them are.

Okay, so if I scroll down into our article, I can begin to see we have a few things going on here. We have a table of quickFacts, we have the actual content of the article is in the page now, and right down here, towards the middle, about line 59 or so, we have two images: one is a trail_map and one is the elevation of the trail. Now obviously not every single image that you might have within the flow content needs a figure. Absolutely not. But in this case, if you think about what these images are, they are a trail map of the trail that the article is talking about and they're an illustration of the trail elevation.

Then that's a natural fit for a figure element, because there is a distinct relationship between these images and the content itself. So what we're going to do is we're just going to go ahead and wrap both of these guys in a figure element. So we're just going to go ahead and do figure and just go ahead and wrap those. Now in this case, I do want to do a figure caption. So remember, this is entirely optional, but I want to let people know kind of what these images represent, and a figcaption is perfect for that. So we're going to do a figcaption tag, and then inside the figcaption, I'm just going to type in 'Trail Map and Elevation', and then I'll just close out the figcaption tag. Okay, excellent! So now I'm going to save this and preview this in my browser.

And I'm just going to scroll down a little bit so I can see my figure, and here we go. And I can see the figcaption for them right here, Trail Map and Elevation. Now because this is in a figure element-- remember figure elements are sectioning roots, so this is not going to show up in a document outline or affect our document online at all-- the figcaption is displaying, and right now it's displaying above the images, which I like, and that's kind of where I want it, but you can place it anywhere that you'd like. If we go back into our code, notice that we could take the figcaption and we could move it from here and place it at the bottom of our figure, and then if we preview that, notice it will show up right there at the bottom.

So it's really up to you in terms of where you want this. Now I want some consistent styling here. If I look at my table, I can see that Trail Info is really the caption of the table itself. I wanted to look similar to that, maybe not quite as big, but at least a little similar to that, to identify what this is. So I want to get back into my code. I am going to move figcaption back to the top of figure. So if you've moved it along with me, I'm just going to go ahead and move that back, and I need to go ahead and open up my main style sheet. Now the main.css, you can find this in the 05_01/_css directory.

So you want to go in there and open up main.css. There we go. And I am going to scroll down. On line 203, I have a little line there that says, "figcaption styles go here," and we're just going to do a little selector here. So we're going to say 'section#trailReviews figcaption'. We're starting to see some of the benefits of using the IDs that we created earlier. We're actually able to say, hey, go find a section with an ID of trailReviews, anytime you find a figcaption inside of it, I want you to style it this way.

So, again, opening and closing curly braces. Now obviously this is not a CSS title. So if you don't know CSS, just follow along with me, type in exactly what I type, and this will work. If you do know CSS, then you know exactly kind of what we're doing here. So what I'm going to do is I am going to do a text-transform and I'm just going to transform the text to all uppercase. And then I am going to change the color of it. I am going to change the color to #4d4d4d. It's kind of a gray. And then finally, I want to change the font size and I am going to adjust the font size to 1.2em to make it a little larger and then go ahead and save that.

And once again we're going to go ahead and preview our page in our browser. And cool, we can see the stylistic change we've made to our figcaption. So we could add a little bit of margin or padding to it if we wanted to, if we wanted a little bit of space there, but I think it's looking okay. Now keep in mind that figure can be used for a lot of different types of content. We used an image here so obviously images, code samples, videos, any graphs you might have, canvas--really any data that illustrates the related content can be contained within a figure element.

This helps to find the relationship of the illustrative content to the rest of the content and helps you group that content in a very meaningful way.

Show transcript

This video is part of

Image for HTML5: Structure, Syntax, and Semantics
HTML5: Structure, Syntax, and Semantics

46 video lessons · 37581 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 2m 20s
    1. Welcome
      48s
    2. Using the exercise files
      1m 32s
  2. 18m 41s
    1. A brief overview of HTML5
      3m 57s
    2. What's in the HTML5 specification?
      8m 17s
    3. Why do we need new structural elements?
      6m 27s
  3. 50m 33s
    1. Defining HTML5 documents
      5m 5s
    2. HTML5 syntax
      9m 14s
    3. The header element
      5m 22s
    4. The nav element
      4m 55s
    5. The section element
      4m 51s
    6. The article element
      4m 48s
    7. The aside element
      4m 13s
    8. The footer element
      4m 17s
    9. Content model overview
      7m 48s
  4. 35m 28s
    1. Understanding the outline algorithm
      3m 17s
    2. Creating document sections
      8m 25s
    3. Using headings properly
      9m 1s
    4. Using hgroup to override sectioning
      4m 17s
    5. Properly nesting structure
      7m 17s
    6. Sectioning roots
      3m 11s
  5. 58m 30s
    1. Organizing content
      4m 41s
    2. Planning document structure
      5m 47s
    3. Choosing the right structural element
      4m 43s
    4. Checking document outlines
      5m 27s
    5. Coding initial page structure
      5m 28s
    6. Using class and ID attributes
      5m 31s
    7. Structuring headers
      13m 13s
    8. Building navigation
      7m 1s
    9. Structuring footers
      6m 39s
  6. 1h 27m
    1. Working with figure and figcaption
      7m 12s
    2. Grouping content with asides
      3m 46s
    3. Using divs in HTML5
      5m 0s
    4. Working with lists in HTML5
      7m 10s
    5. The return of bold and italic
      5m 52s
    6. Citing works semantically
      6m 32s
    7. Using the address element
      5m 24s
    8. Using the small element
      4m 24s
    9. Using the mark element
      5m 16s
    10. Working with date and time
      11m 55s
    11. Creating block-level links
      8m 53s
    12. Understanding link relationships
      9m 28s
    13. Defining link relationships
      6m 23s
  7. 17m 22s
    1. Current browser support
      7m 38s
    2. Ensuring block-level display
      4m 3s
    3. Adding support for elements in older browsers
      5m 41s
  8. 3m 46s
    1. Additional Resources
      3m 46s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed HTML5: Structure, Syntax, and Semantics.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.