Skip to main content
March 23, 2026/5 min read

HTML & CSS Intro Course: Divs, IDs, & More

Master HTML Structure with Divs and CSS Styling

What You'll Learn

This tutorial covers essential HTML structure concepts including div tags, CSS styling, the box model, and responsive design principles for creating professional web layouts.

Key HTML & CSS Concepts

Div Tags

Block-level containers that stack vertically and wrap content sections. Essential for page structure and layout organization.

IDs vs Classes

IDs are unique identifiers used once per page with hashtag syntax. Classes can be reused multiple times with period syntax.

Box Model

Understanding padding, margins, borders, and how they affect element spacing and layout on your webpage.

Ready to advance your web development skills? Continue learning HTML & CSS fundamentals in our comprehensive NYC Web Development classes. For professionals outside New York, explore and compare the best HTML & CSS classes near you or join our live online HTML & CSS classes designed for working professionals.

Video Transcription

Let's explore div tags and IDs—essential tools for structuring professional web layouts. Currently, this page contains basic HTML elements: headings, paragraphs, and content that stretches uncomfortably across the full browser width. This creates a poor user experience, as wide text blocks become difficult to read and appear unprofessional.

Professional web design requires thoughtful content constraints and visual hierarchy. We need to limit our content width and implement strategic background colors to create visual separation between the page background and content area. This approach draws attention to the main content while improving readability across all device sizes.

To achieve this design, we need multiple containers working in harmony. While the body tag serves as our page-level container, we require an additional wrapper for our content area. This allows us to apply different background colors: one for the overall page (applied to the body) and another for the content section itself.

Let's start by establishing our page foundation with a background color on the body tag. The body element wraps all visible content, making it the logical choice for page-wide styling. When working with design teams, you'll typically receive specific color specifications—hex codes that ensure brand consistency across your web properties.

I'll apply the background color provided in our design specifications. In professional development, designers typically provide detailed style guides with exact color values, typography specifications, and spacing requirements. This collaborative approach ensures pixel-perfect implementation of approved designs.

After saving and refreshing, you'll notice the entire page adopts this new background color, overriding the browser's default white background. This demonstrates a fundamental web development principle: CSS allows us to override browser defaults with custom styling that reflects our brand and design requirements.

Now we need to make our content stand out against this darker background. The goal is to create a contained, well-defined content area with a white background and subtle border treatment. This approach is commonly used in modern web design to improve content readability and create visual focus.

Since we need an additional container element, we must wrap our content in a new HTML tag. This brings us to an important distinction in HTML: the difference between span and div elements. Understanding when to use each is crucial for proper semantic markup.

Span tags are inline elements, similar to images—they flow horizontally alongside other content. If you create three span elements, they'll appear side by side. Div tags, however, are block-level elements like headings and paragraphs. They stack vertically, creating distinct sections that serve as building blocks for page layout.

For our content wrapper, a div tag is the appropriate choice. We're creating a major content section that should occupy its own horizontal space and stack properly with other page sections. This follows established web standards and ensures our markup remains semantic and accessible.

I'll create a div tag immediately inside the body element, wrapping all existing content. This creates a clean hierarchy: body contains div, div contains all page content. This structure provides the foundation for responsive design and future layout enhancements.

Professional web development requires organized, maintainable code. Since pages typically contain multiple div elements, we need a systematic naming approach. We have two options: classes and IDs. Both serve to identify elements, but they have distinct use cases and technical implications.

For this page wrapper—a unique element that appears once per page—an ID is most appropriate. IDs are designed for unique page elements, while classes are intended for reusable styling patterns. This distinction becomes critical as applications scale and teams collaborate on larger codebases.

Let me demonstrate the difference between classes and IDs. I'll assign an ID of "wrapper" to our div element. The naming convention is crucial here: IDs cannot contain spaces and should be descriptive of their function. You can use dashes or underscores for word separation, and while capitalization is technically allowed, maintaining consistent lowercase naming prevents case-sensitivity issues.

Choose names that clearly describe the element's purpose—"wrapper," "container," or "page-content" are all appropriate choices. Avoid generic names or references that don't convey meaning to other developers who might work on your code. Good naming conventions are essential for code maintainability and team collaboration.

The key distinction to remember: IDs must be unique within a page (use each ID only once), while classes can be applied to multiple elements. This makes IDs perfect for unique page sections and classes ideal for repeated styling patterns like buttons, cards, or text formatting.

When referencing IDs in CSS, use the hash symbol (#). So "#wrapper" targets an element with an ID of "wrapper." This selector syntax is fundamental to CSS and you'll use it constantly in professional development. Classes use a period (.) as their selector prefix, making the distinction clear in your stylesheets.

Now I can style our wrapper element. I'll add a white background color using the hex code #FFFFFF. Here's a professional tip: when all three color pairs in a hex code are identical (like FF-FF-FF), you can abbreviate it to three characters (#FFF). This shorthand notation is widely supported and helps keep stylesheets concise.

Div vs Span Elements

FeatureDiv TagsSpan Tags
Display TypeBlock-levelInline
Layout BehaviorStack verticallyFlow horizontally
Use CaseLarge content sectionsSmall text portions
Default WidthFull container widthContent width only
Recommended: Use div tags for main content containers and page structure

Creating a Page Wrapper

1

Add Background to Body

Set a background color on the body tag to establish the page's base color scheme

2

Create Div Container

Wrap all content in a div tag to create a distinct content area separate from the page background

3

Assign ID to Div

Give the div a unique ID like 'wrapper' to target it with CSS styling rules

4

Style with CSS

Use hashtag syntax to reference the ID and apply width, background, padding, and margin properties

CSS Selector Syntax

Remember: hashtag (#) targets IDs, period (.) targets classes. IDs should be unique per page, while classes can be reused multiple times.

Width vs Max-Width

Pros
Max-width allows content to shrink on smaller screens
Prevents horizontal scrolling on mobile devices
Maintains readability across different screen sizes
More responsive and user-friendly approach
Cons
Fixed width forces exact size regardless of screen
Creates horizontal scrolling on small screens
Poor mobile user experience
Content may be too wide or too narrow

Box Model Properties

Padding

Space inside the element between content and border. Increases the internal breathing room and improves readability.

Margin

Space outside the element between it and other elements. Use 'margin: auto' to center block elements horizontally.

Border

Visible boundary around the element. Specify size, style (solid/dotted/dashed), and color properties.

Centering Elements

To center a block element horizontally, set a max-width and use 'margin: auto'. This automatically distributes equal margins on left and right sides.

In general, you want to probably put some sort of limits on the width of your page to make it look better
Wide text paragraphs become difficult to read, making width constraints essential for good user experience

CSS Best Practices

0/5
Responsive Design Principle

Using max-width instead of fixed width allows your content to adapt to different screen sizes, creating a better user experience across desktop, tablet, and mobile devices.

Key Takeaways

1Div tags are block-level elements that stack vertically and are essential for creating page structure and content containers
2IDs are unique identifiers used once per page and referenced with hashtag syntax, while classes can be reused and are referenced with period syntax
3The box model consists of padding (inside space), margins (outside space), and borders, which control element spacing and layout
4Use max-width instead of fixed width to create responsive designs that work well on different screen sizes
5Center block elements horizontally by setting a max-width and using 'margin: auto' to distribute equal left and right margins
6Background colors on containers help distinguish content areas and improve visual hierarchy on web pages
7Shorthand CSS properties like 'border' are more efficient than longhand properties and keep code DRY
8Setting fonts and styles on parent containers allows child elements to inherit properties, making code more maintainable and consistent

RELATED ARTICLES