New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

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

Understanding the relationship between HTML and CSS

From: Up and Running with HTML

Video: Understanding the relationship between HTML and CSS

It's hard to find two technologies as intertwined as HTML and CSS; indeed, it's almost impossible to teach one without at least mentioning the other. In this chapter we're going to take a brief look at styling so that you can see how these technologies work together and gain an understanding of where HTML's capabilities end and where CSS takes over. I want to start by giving you an overview of how HTML and CSS work together. I have, from the 06_01 folder, I've got the styles.htm opened up in the browser.

Understanding the relationship between HTML and CSS

It's hard to find two technologies as intertwined as HTML and CSS; indeed, it's almost impossible to teach one without at least mentioning the other. In this chapter we're going to take a brief look at styling so that you can see how these technologies work together and gain an understanding of where HTML's capabilities end and where CSS takes over. I want to start by giving you an overview of how HTML and CSS work together. I have, from the 06_01 folder, I've got the styles.htm opened up in the browser.

The page structure is very, very simple. You can see we have a heading 1 at the very top of the page, 3 paragraphs, and then a heading 2. It looks like we're looking at unstyled content, but we're really not. Every single browser has its own default styles. This is Firefox, and Firefox basically says, "okay, if you don't see the styles, go ahead and take heading 1 and make it bold and make it this big and use whatever font the user has told me to use," which is in this case is Times New Roman and Georgia. Internet Explorer has it's own default styles, Chrome has it's own, Opera has it's own, so forth and so on.

It just so happen that most of those default style look very similar to each other, if not exactly the same. That's why this pages, when no CSS has been attach to him at all, look very much the same in every browser. I'm kind of tricking you right now, because if you open this file up in Firefox I bet you're looking at it and saying "it doesn't look anything like it looks on your screen." Well, that's because right now in Firefox, I'm telling Firefox not to render my styles so that you can sort of see the "unstyled content." So if I go up and I say let's change the page style, let's go ahead and use the style that I wrote for the page, you can see it looks very, very different.

CSS is affecting a lot here. It's affecting how the text is formatted in terms of the typography. It's affecting where it's positioned on the page. It's affecting its width. As you can see as I scroll the page, it's affecting the functionality. This header that was down one the bottom of the page is now over here on the right-hand side, and it doesn't respond to scrolling whereas the HTML and CSS paragraphs over there do. If I go back into our code, all it takes to do, what I was just showing you, is right here.

These are CSS styles. Now the same way that HTML syntax is pretty darn easy to learn, CSS syntax is maybe even easier to learn, and that's because the syntax for CSS is made up of three major things. You have the selector, and in the case of body that's the selector for body. The selector is what tells the browser which element or elements on the page should I target and style. I'm using very simple selectors here, but selectors can get a lot more complex.

So you can use selectors to sort of filter out where your styles are being applied. And then you have properties that you're changing--in this case margin--and then values. So you have selectors, properties, and then the values or the new values that you're setting for them. When you learn CSS the syntax is incredibly easy to learn, but the complex part of it obviously is learning how to write selectors to target things appropriately and properly and filter out things, which properties you can set, and then which values you can set on those properties.

And there's a lot to learn there obviously, but that's really all there is to it. Just to show you how much of a change you can make in something just by changing the styles, I'm going to take the first set of styles here and I'm going to go ahead and comment those out. And then I'm going to take this little block of styles I have here below this. It's already commented, so it's like one of the good cooking shows, you know where you've already got stuff in oven. I already had that stuff in the oven ready to go. So, if you're looking for the structure of the HTML it's this. There is a very simple page and then here's the CSS itself.

So now I save this and go back to my browser and refresh it, an entirely new set of styles, an entirely different look and feel. But here's the most important part of this demonstration. Yes, it's really cool that CSS has this capability; it's really cool that we can make such a dramatic change, but here's the really important part: the underlying structure of the page never changed, not once. All those paragraphs are still there, the headings are still there, so the only thing I've affected here is the visual aspect of it, and that's the really cool thing about HTML and CSS working together.

There is the separation, if you will, of structure and presentation. HTML handles the structure of your page; CSS handles the presentation. So, unless you work in an environment where your styles are totally locked down and you don't have access to them at all, learning CSS is an equally critical part of learning web design. So for the remained to the chapter we're going to take a closer look at styles.

Show transcript

This video is part of

Image for Up and Running with HTML
Up and Running with HTML

49 video lessons · 25181 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 2m 12s
    1. Welcome
      55s
    2. Using the exercise files
      1m 17s
  2. 29m 30s
    1. Learning HTML
      2m 47s
    2. Choosing a code editor
      5m 2s
    3. Exploring basic HTML syntax
      8m 18s
    4. Do I need to learn HTML5?
      5m 6s
    5. Exploring HTML references
      8m 17s
  3. 35m 40s
    1. Exploring an HTML document
      5m 19s
    2. Working with doctype declarations
      4m 3s
    3. Examining the document head
      8m 20s
    4. Looking at the document body
      3m 21s
    5. Adding document structure
      8m 52s
    6. Lab: Coding a basic page
      3m 9s
    7. Solution: Coding a basic page
      2m 36s
  4. 1h 23m
    1. How does HTML format text?
      5m 51s
    2. Adding headings
      7m 24s
    3. Formatting paragraphs
      4m 54s
    4. Controlling line breaks
      3m 50s
    5. Creating lists
      10m 37s
    6. Emphasizing text
      6m 42s
    7. Displaying special characters
      5m 8s
    8. Controlling whitespace
      4m 35s
    9. Inserting images
      9m 20s
    10. Lab: Controlling page content
      13m 57s
    11. Solution: Controlling page content
      10m 55s
  5. 31m 54s
    1. Linking to pages within your site
      6m 45s
    2. Linking to external pages
      3m 2s
    3. Linking to downloadable resources
      2m 25s
    4. Linking to page regions
      8m 0s
    5. Lab: Creating Links
      5m 57s
    6. Solution: Creating Links
      5m 45s
  6. 40m 27s
    1. Examining basic table structure
      5m 10s
    2. Adding content to tables
      6m 20s
    3. Setting table attributes
      7m 42s
    4. Adding table captions
      4m 3s
    5. Defining table headers
      2m 13s
    6. Making table data accessible
      5m 46s
    7. Lab: Building tables
      4m 13s
    8. Solution: Building tables
      5m 0s
  7. 43m 23s
    1. Understanding the relationship between HTML and CSS
      4m 58s
    2. Creating inline styles
      4m 53s
    3. Exploring the style element
      5m 13s
    4. Basic font styling
      9m 24s
    5. Changing color
      4m 55s
    6. Taking styles further
      5m 24s
    7. Lab: Controlling basic styles
      5m 10s
    8. Solution: Controlling basic styles
      3m 26s
  8. 5m 44s
    1. Next steps
      2m 56s
    2. Additional resources
      2m 48s

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

Are you sure you want to delete this note?

No

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.