Chapter 3
Table of contents
- Creating a menu with HTML and CSS
- Embedding images
- Embedding Videos (1 of 2)
- Building tables
- Styling tables
- Creating HTML forms
1. Creating a menu with HTML and CSS
1.1 Website navigation and user experience
A website menu is crucial for visitors to navigate a site, directly influencing the overall user experience. This experience encompasses the site's look, feel, color scheme, navigation, fonts, and the information presented.
- User experience: The overall impression or emotion a visitor has when interacting with a website.
- Navigation influences: Key aspects include the site's structure, placement of menu items, and the clarity of menu text.
1.2 Designing a user-friendly menu
Effective menu design follows several guidelines to ensure ease of use and accessibility.
- Three-click rule: Users should be able to reach any content on the site within three clicks.
- Consistency: Navigation structure and placement should remain consistent across all pages, with the homepage potentially being an exception.
- Menu item organization: Links can point directly to pages or to sub-menus. Avoid overwhelming users with too many options at once.
- Descriptive text: Menu item labels should be simple and self-explanatory, such as "Home," "Products," or "About Us."
- Search functionality: A search feature, located on or near the menu, is beneficial for complex or extensive websites.
1.3 HTML5 structural elements
HTML5 introduced semantic tags to define common website structures, improving organization and accessibility.
<header>: Typically contains introductory content or navigational links for a page or section.<nav>: Encloses the main navigation links of a website.<section>: Represents a thematic grouping of content, usually with a heading.<footer>: Contains information about the author, copyright data, or related links at the bottom of a page.
1.4 Constructing a menu with an unordered list
An unordered list (<ul>) is a common and effective way to structure menu items in HTML.
- HTML structure: Menu items are placed within
<li>(list item) tags inside the<nav>element. - Links: Each
<li>typically contains an<a>(anchor) tag, linking to another page within the site.
1.5 Styling an unordered list menu
CSS is used to transform the default appearance of an unordered list into a functional and visually appealing navigation menu.
- Body and HTML height: Setting
height: 100%;for bothhtmland body ensures the page content can occupy the full viewport height. - Display block: HTML5 structural elements like
<footer>,<header>,<section>, and<nav>are styled withdisplay: block;to ensure they occupy their own space. - Floating elements: When an element is floated (e.g., to the left), other content can flow around it. This can affect the layout of block-level elements.
- Navigation styling: Specific styles can be applied to the
<nav>element, includingwidth,float,margin-right, andmargin-top. - List styling: To remove default bullet points and adjust spacing, properties like
list-style-type: none;,padding-left: 0;, andtext-indent: 5px;are used.background-colorandline-heightcan also be adjusted. - Rounded corners:
border-radius: 5px;can be applied to give the menu a softer appearance.
1.6 Styling menu items and links
Further styling enhances the interactivity and appearance of individual menu items and their links.
- List item hover effect: The
:hoverpseudo-class in CSS allows for styling changes when a user's mouse pointer is over a list item (<li>). This can include changing the background color. - Link styling: Styles can be applied specifically to the anchor (
<a>) tags within the list items to control text color, remove underlines, and adjust spacing. The selectornav ul li atargets these links precisely.
📝 When a user hovers their mouse over a menu item like "Products," its background color changes from a light gray to a light blue, providing visual feedback that the item is interactive.
2. Embedding images
2.1 The <img> tag
The <img> tag is fundamental for embedding images into a webpage. It is a self-closing tag and requires attributes to provide necessary information.
idattribute: Assigns a unique identifier to the image element, useful for targeting with CSS or JavaScript.altattribute: Provides alternative text that displays if the image fails to load or for screen readers used by visually impaired users. This is crucial for accessibility.
2.2 Resizing images
Images can be resized either through image editing software before uploading or directly using CSS.
- CSS resizing: Style rules can specify
widthandheightfor images. For example,section img#home_page_img {width: 560px; height: 400px;}applies specific dimensions to an image with the IDhome_page_imgwithin asection.
📝 An image intended for a specific content area is resized using CSS to fit perfectly within its designated space without distorting its aspect ratio.
2.3 Adding an image border
Borders can visually frame an image, helping to define its boundaries and making it appear more intentional within the page layout.
- CSS class for borders: A CSS class, such as
.img_border, can be defined to apply border styles consistently. - Applying the class: This class is then added to the
<img>tag in the HTML using theclass="img_border"attribute.
📝 An image of a product is given a thin, solid black border using the
.img_borderclass, making it stand out from the background and clearly delineating its edges.
2.4 Creating image maps
Image maps allow specific regions within an image to act as clickable links, directing users to different web pages or resources.
<map>element: Defines the image map itself, with anameattribute that uniquely identifies it.<area>element: Within the<map>,<area>tags define individual clickable regions.coordsattribute: Specifies the coordinates of the clickable area, typically relative to the image's upper-left corner.
2.5 Best practices for using images
Wise image usage enhances user experience and website performance.
- Copyright: Always use images you have the rights to use; avoid copyrighted material without permission.
- Alt text: Provide descriptive
alttext for all images to ensure accessibility. - Avoid image-only sites: Do not construct an entire website solely from images, as this hinders SEO and accessibility.
- Avoid image-based navigation: Critical elements like menus should not be implemented as images, as they are not easily searchable or accessible.
2.6 Guidelines for image quality and presentation
Further guidelines focus on the visual quality and context of images.
- Image sizing: Optimize image file sizes for faster loading times without sacrificing quality.
- Descriptions/Captions: Include text descriptions or captions immediately above or below images to provide context.
- Composition: Use well-composed, high-quality photographs taken with a good camera for professional results.
2.7 Images and responsive design
Responsive design ensures that webpages adapt gracefully to various screen sizes, especially mobile devices.
<picture>tag: The<picture>element allows developers to specify different image sources for different screen resolutions or device capabilities, optimizing image delivery for a responsive experience.
3. Embedding Videos (1 of 2)
3.1 The <video> tag
The <video> tag is used to embed video content directly into an HTML page, providing control over its size and fallback content.
widthandheightattributes: These attributes control the dimensions of the video player displayed on the page.- Fallback content: Any text placed between the opening and closing
<video>tags will be displayed if the browser does not support the video format or cannot find the video file.
3.2 Embedding online videos
Embedding videos from popular platforms like YouTube or Vimeo is a common practice, often utilizing <iframe> tags.
<iframe>tag: This tag embeds content from another source, such as a video player from a video hosting service, into the current HTML document. The source URL is specified using thesrcattribute.
📝 A YouTube video is embedded on a webpage using an
<iframe>tag, allowing users to watch the video directly within the page without leaving the site.
4. Building tables
4.1 Creating table structure
HTML tables are built using a set of elements that define rows, columns, and cells, organizing data in a structured grid.
<table>element: The main container for the entire table.<tr>element: Defines a table row.<th>element: Defines a header cell within a row, typically used for column or row titles. Text within<th>is usually bold and centered.<td>element: Defines a standard data cell within a row.- Indentation: Proper indentation of HTML table code is crucial for readability and maintainability.
4.2 Adding table borders
Borders are essential for visually separating table cells and defining the table's structure. They are typically applied using CSS.
- Outer border: A border can be applied to the entire
<table>element usingborder: 2px solid black;. - Inner borders: Borders for individual cells (
<td>and<th>) can be added usingborder: 1px solid rgb(175,175,175);. border-collapseproperty: Settingborder-collapse: collapse;merges adjacent cell borders into a single, cleaner border, preventing double lines.- Table width: The
width: 80%;property sets the table to occupy 80% of its containing element's width.
| Element | Description |
|---|---|
| table | The main container for the table. |
| tr | Defines a table row. |
| th | Defines a header cell. |
| td | Defines a data cell. |
4.3 Combining border styles
You can combine different border styles for the table's exterior and its internal cells to create a visually distinct structure.
- Outer border: A thicker border around the entire table.
- Inner borders: Thinner borders between individual cells.
border-collapse: collapse;: Ensures that adjacent borders are rendered as a single line, creating a unified appearance.
📝 A product catalog table features a thick black border around the entire table and thin gray borders between each product's details, making the data easy to scan.
4.4 Activity 3.1 Knowledge Check
This activity tests understanding of basic HTML and image concepts.
- Question 1: True or false: Block-level elements make a space for themselves that other elements can’t also occupy in a webpage.
- Question 2: The ____ attribute is used to display text on the screen if the image doesn’t load due to an incorrect file path.
- Question 3: A(n) ____ is an image with clickable links.
4.5 Activity 3.1 Knowledge Check Answers
- Answer 1: True. Block-level elements occupy the full width available and start on a new line.
- Answer 2:
alt. Thealtattribute provides alternative text for images. - Answer 3: Image map. An image map defines clickable regions within an image.
5. Styling tables
5.1 Adding row styles
Styling rows, particularly using alternating background colors (banded rows), improves readability and helps users track data across columns.
nth-child(even)pseudo-class: This CSS selector targets every even-numbered row (<tr>) within the table.background-color: Applying a light background color to even rows makes them visually distinct from odd rows.
📝 In a table listing customer orders, every second row has a pale blue background, making it easier to follow the details of each individual order.
5.2 Adding column styles
Specific columns can be styled to highlight important data, such as prices or quantities.
<colgroup>and<col>elements: These elements allow you to group columns and apply styles to them collectively.col.priceselector: By assigning a class (e.g.,price) to a<col>element representing the price column, you can target it with CSS.- Highlighting: Applying a distinct
background-colorto the price column makes it stand out.
| Element | Purpose |
|---|---|
| colgroup | Groups columns within a table for styling purposes. |
| col | Defines a column within a colgroup and can be styled individually or by class. |
📝 The "Price" column in a product table is styled with a light yellow background, drawing immediate attention to the cost of each item.
5.3 Creating an interactive table
Interactivity can be added using the :hover pseudo-class to provide visual feedback when a user's mouse pointer is over a table row.
tr:hoverselector: This CSS rule applies styles specifically when the mouse pointer hovers over a table row (<tr>).- Visual indicator: Changing the
background-colorof the hovered row provides a clear visual cue, helping users identify the row they are currently interacting with. - Style precedence: The
:hoverstyle typically overrides other row styles, such as banded row colors, to ensure the hover effect is prominent.
📝 As a user moves their mouse over a row in a data table, that row briefly highlights with a soft cyan color, indicating it is the currently selected row.
6. Creating HTML forms
6.1 Building the HTML form structure
HTML forms are created using the <form> element, which acts as a container for various input controls that allow users to submit data.
<form>element: Encloses all form elements and specifies how the data will be submitted (e.g., usingmethodandactionattributes).<fieldset>element: Groups related form controls, often used to organize complex forms.<legend>element: Provides a caption or title for the<fieldset>, improving usability.<label>element: Associates text with a form control, enhancing accessibility by providing descriptive labels that can be clicked to focus the associated input.<input>element: The most common element for data entry, with itstypeattribute determining its behavior (e.g., text, password, checkbox, radio button).- Submit button: Created using
<input type="submit">, this button triggers the form submission process.
6.2 HTML form elements and types
HTML provides a variety of input types to accommodate different kinds of user data.
type="text": For single-line text input.type="email": For email address input, often with built-in validation.type="password": For password input, masking characters.type="checkbox": For selecting one or more options from a set.type="radio": For selecting a single option from a set.type="submit": To submit the form data.type="reset": To clear all form fields.
| Input Type | Description |
|---|---|
| text | A single-line text input field. |
| An input field for email addresses, with validation. | |
| password | A password field where characters are masked. |
| checkbox | A checkbox that can be checked or unchecked. |
| radio | A radio button for selecting one option from a group. |
| submit | A button that submits the form data. |
| reset | A button that resets all form fields to their default values. |
📝 A visitor feedback form includes fields for name (
type="text"), email (type="email"), and a comment box (type="textarea"), along with a "Send Feedback" button (type="submit").
6.3 Case Study: Creating a new page
This case study involves creating a new HTML page and applying styling to lists.
- Task: Create a page named
causes.html. - Content: Add bulleted lists for worthy causes, favorite entertainment sites, and similar products.
- Styling: Apply appropriate styles, including a background color to the lists.
6.4 Self-Assessment Questions
These questions prompt reflection on key concepts covered in the chapter.
- Question 1: Describe two places where users expect to find website menus.
- Question 2: What are the four rules for using images correctly in a website and why is each one important?
- Question 3: How does a border for an image significantly improve the user experience of a webpage?
- Question 4: Describe three guidelines a programmer should follow to make website videos as accessible as possible.
© 2026 Maeve. All rights reserved. This content is protected by copyright.