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

Using block and inline tags

From: HTML Essential Training

Video: Using block and inline tags

HTML provides two distinct display modes; block and inline. Let's start by looking at inline elements. I'll make a working copy of inline.html and rename the copy to inline-working.html. I am going to open that in my text editor and see it's just a paragraph of Lorem Ipsum, and in the middle of that is an image tag. It'll just display a small picture of a rock inline, and so this is called Inline mode. I am going to go ahead and reduce the width of this and I am going to turn on Wrapping there, and we'll open it also in the browser using Firefox, so we can see both of these side-by-side.

Using block and inline tags

HTML provides two distinct display modes; block and inline. Let's start by looking at inline elements. I'll make a working copy of inline.html and rename the copy to inline-working.html. I am going to open that in my text editor and see it's just a paragraph of Lorem Ipsum, and in the middle of that is an image tag. It'll just display a small picture of a rock inline, and so this is called Inline mode. I am going to go ahead and reduce the width of this and I am going to turn on Wrapping there, and we'll open it also in the browser using Firefox, so we can see both of these side-by-side.

And there you can see in the browser there is the image inline with the paragraph, so it flows with the paragraph. You see it's a little taller than the characters in the paragraph and so it makes some space for itself. But because the image element is an inline element, it just flows with the text and that's what inline means. Inline elements are elements that flow inline with text. There are other examples of inline elements, for example, we can come in here and we can make a link.

I am just going to take this word Pellentesque and make it a link. It's not linking to anything, but if I save that and reload in the browser, you see that that is now a link and my cursor changes when it hovers over it. So the a element for creating links is also an inline element. The b and i elements are inline, so I want to make this bold here. That's a container. And I am going to make this part here italic with an i element, and save that, and come over here and reload, and you see there is our bold and there is our italic.

So those are also inline elements and they flow with the text. It's possible to change an inline element to a block display. If I come in here to the image and move this down to the next line, I am going to say style=. I am going to say display: block and that changes the display mode of this element to block mode. If I save that and reload, you'll notice that that image is now on a line by itself. It actually interrupts the paragraph, because a block mode element is not allowed inside a paragraph. A paragraph can only have inline elements.

And so because the browser sees that block element, it ends the paragraph, and then it starts another paragraph after it. So now that it's a block element, let's go ahead and bring in a bigger picture of the rock. If I take out -small there I'll get a bigger picture. I'll save that and reload, and there is a bigger of the rock. And now I can actually make that float to the right and have the text wrap around it. By inside of my style here I just say semicolon and float, colon right, and I can terminate that with another semicolon, and I come over here and reload, and now you see that it floats to the right and the paragraph wraps around it.

That's because I have this float right and it's in block mode. So if you have an image or another inline level element that you want to treat as block level, it's possible to do this, and it's not an uncommon thing to do. Now let's take a look at an example of a block level element. I am going to go ahead and I am going to close this, and I am going to close that, and we'll come over here to block.html, and I'll make a working copy and block-working.html, open that in my text editor.

We can see that here we have, instead of paragraphs we have divs, and there's one div, an outer div here, and if I collapse that you'll see that that goes all the way down to the body, so it ends here. In the middle of that div is another div, and this is why I am not using a paragraph here, because a div is allowed to have other divs, and other block level elements inside of it. A paragraph is not allowed to do that. And so there is a div in the middle and an outer div and a bunch of Lorem Ipsum in each part of that.

And so we'll go ahead and we'll shrink this and turn on Soft Wrap. I am going to go ahead and open that in my browser. And you can see I've highlighted this middle div in yellow, and you can see that it says div style="background: yellow" and that makes it highlighted like this in yellow. So div is a block level element, and this is an unusual usage of div and normally we would use paragraphs for this, but because we're just demonstrating block level elements, it's just a convenient way to do that.

And we have this div in the middle of the divs, and so you see that it takes up a vertical space by itself; block level elements take up vertical space. They don't just flow with things. They take up vertical space. Like I changed the image to block level, I can do the same thing with div, I can change this to inline level. Within the stylesheet I can say; display: inline; and save that, and when I reload, you see now it's flowing with the text. So it's no longer taking up vertical space. It's taking up inline space. It just flows with the text right like that with the rest of the text as you would expect to say of an image or a link or bold or something.

So if I undo this, I am just pressing Command+Z on this Mac or Ctrl+Z on a PC to undo that, and I am going to change this instead. I am going to say span instead of div. So span is like div, but it's inline. I save that and reload over here. You see it's still inline like that. If I change this back to div, it will now be block level, save and reload. Now it's block level again. So div is naturally a block level element and span is naturally a inline level element.

So I can take this div and I can float it to the right. I can say float: right. And I also need to give it a width that's smaller than the width that's there, so if I say width: 100 pixels, now it will be a hundred pixels wide and it will float to the right, and you see all the other text wraps around it, just like we did with the image. So block level elements take up vertical space. They are designed to contain other block and inline level elements. The exception to that is paragraphs. Paragraphs cannot contain other block level elements.

Inline level elements flow with text. They are designed to flow and to contain other inline level elements that also flow. We'll see more examples of block and inline elements as we go through the rest of the course.

Show transcript

This video is part of

Image for HTML Essential Training
HTML Essential Training

82 video lessons · 101160 viewers

Bill Weinman
Author

 
Expand all | Collapse all
  1. 5m 24s
    1. Welcome
      56s
    2. Using the exercise files
      1m 37s
    3. What you need to know about this course
      2m 51s
  2. 22m 0s
    1. What is HTML?
      4m 12s
    2. Examining the structure of an HTML document
      7m 50s
    3. Understanding tags and containers
      6m 4s
    4. Exploring content models in HTML5
      2m 23s
    5. Looking at obsolete elements
      1m 31s
  3. 27m 19s
    1. Understanding whitespace and comments
      3m 53s
    2. Displaying text with paragraphs
      3m 37s
    3. Applying style
      8m 5s
    4. Using block and inline tags
      6m 34s
    5. Displaying characters with references
      5m 10s
  4. 16m 36s
    1. Exploring the front matter of HTML
      2m 9s
    2. Applying CSS to your document
      3m 59s
    3. Adding scripting elements
      4m 54s
    4. Using the meta tag
      3m 34s
    5. Optimizing your page for search engines
      2m 0s
  5. 24m 59s
    1. Controlling line breaks and spaces
      2m 46s
    2. Exploring phrase elements
      1m 44s
    3. Using font markup elements
      1m 5s
    4. Highlighting text with mark
      1m 29s
    5. Adding headings
      1m 38s
    6. Using quotations and quote marks
      3m 2s
    7. Exploring preformatted text
      1m 45s
    8. Formatting lists
      2m 28s
    9. Forcing text direction
      3m 49s
    10. Suggesting word-break opportunities
      2m 29s
    11. Annotating East Asian languages
      2m 44s
  6. 29m 15s
    1. Introducing CSS
      55s
    2. Understanding CSS placement
      6m 55s
    3. Exploring CSS syntax
      10m 34s
    4. Understanding CSS units of measure
      3m 3s
    5. Some CSS examples
      7m 48s
  7. 22m 5s
    1. Using images
      4m 13s
    2. Flowing text around an image
      4m 55s
    3. Breaking lines around an image
      3m 3s
    4. Aligning images
      5m 25s
    5. Mapping links in an image
      4m 29s
  8. 22m 28s
    1. Understanding URLs
      2m 41s
    2. Working with hyperlinks
      3m 28s
    3. Using relative URLs
      4m 20s
    4. Specifying a base URL
      2m 19s
    5. Linking within a page
      4m 12s
    6. Using image links
      5m 28s
  9. 17m 2s
    1. Exploring list types
      3m 52s
    2. List elements in depth
      7m 44s
    3. Using text menus with unordered lists
      5m 26s
  10. 15m 30s
    1. Introduction to HTML semantics
      4m 9s
    2. Exploring an example
      4m 56s
    3. Marking up figures and illustrations
      2m 33s
    4. Creating collapsible details
      3m 52s
  11. 11m 18s
    1. Embedding audio
      5m 19s
    2. Embedding video
      5m 59s
  12. 11m 53s
    1. Creating ad-hoc Document Object Model (DOM) data with the data-* attribute
      4m 53s
    2. Displaying relative values with meter
      2m 57s
    3. Creating dynamic progress indicators
      4m 3s
  13. 4m 49s
    1. Overview of HTML5 microdata
      1m 8s
    2. Exploring an example with microdata
      3m 41s
  14. 7m 3s
    1. Understanding outlines
      52s
    2. A demonstration of outlining
      6m 11s
  15. 13m 1s
    1. Table basics
      7m 29s
    2. Exploring the semantic parts of a table
      2m 32s
    3. Grouping columns
      3m 0s
  16. 9m 55s
    1. Frames overview
      54s
    2. Using traditional frames
      4m 26s
    3. Exploring inline frames using iframe
      2m 7s
    4. Simulating frames with CSS
      2m 28s
  17. 53m 7s
    1. Introducing forms
      10m 24s
    2. Using text elements
      10m 12s
    3. Using checkboxes and radio buttons
      2m 37s
    4. Creating selection lists and dropdown lists
      5m 14s
    5. Submit and button elements
      8m 48s
    6. Using an image as a submit button
      2m 15s
    7. Keeping context with the hidden element
      3m 0s
    8. Setting tab order
      2m 7s
    9. Preloading an autocomplete list using the datalist feature
      5m 26s
    10. Displaying results with output
      3m 4s
  18. 19m 47s
    1. Touring a complete site
      2m 14s
    2. Touring the HTML
      8m 44s
    3. Touring the CSS
      8m 49s
  19. 29s
    1. Goodbye
      29s

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.

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 HTML Essential Training.

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 preferencesfrom 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.