HTML Chapter 4
HTML Chapter 4
Syntax
<img src="url" alt="alternatetext">
The src Attribute
• The required src attribute specifies the path (URL) to the image.
• Note: When a web page loads; it is the browser, at that moment, that
gets the image from a web server and inserts it into the page.
Therefore, make sure that the image actually stays in the same spot in
relation to the web page, otherwise your visitors will get a broken link
icon. The broken link icon and the alt text are shown if the browser
cannot find the image.
Example
<img src="img_chania.jpg" alt="Flowers in Chania">
The alt Attribute
• The required alt attribute provides an alternate text for an image, if the
user for some reason cannot view it (because of slow connection, an
error in the src attribute, or if the user uses a screen reader).
• The value of the alt attribute should describe the image:
Example
<img src="img_chania.jpg" alt="Flowers in Chania">
• If a browser cannot find an image, it will display the value of the alt
attribute.
Image Size – Height and Width
• You can use the style attribute to specify the width and height of an
image.
Example
<img src="img_girl.jpg" alt="Girl in a jacket"
style="width:500px;height:600px;">
Example
<img src=“../images/html5.gif" alt="HTML5 Icon"
style="width:128px;height:128px;">
Animated Images
• HTML allows animated GIFs:
Example
<img src="programming.gif" alt="Computer Man“
style="width:48px;height:48px;">
Image Floating
• Use the CSS float property to let the image float to the right or to the
left of a text:
Example
<p><img src="smiley.gif" alt="Smiley face"
style="float:right;width:42px;height:42px;">
• The image will float to the right of the text.</p>
JPEG Joint Photographic Expert Group .jpg, .jpeg, .jfif, .pjpeg, .pjp
image
• Each table row is defined with a <tr> tag. Each table header is defined with a <th>
tag. Each table data/cell is defined with a <td> tag.
Example
th, td {
padding: 15px;
}
HTML Table - Left-align Headings
• By default, table headings are bold and centered.
Example
th {
text-align: left;
}
HTML Table - Add Border Spacing
• Border spacing specifies the space between the cells.
• To set the border spacing for a table, use the CSS border-spacing property:
Example
table {
border-spacing: 5px;
}
HTML Table - Cell that Spans Many
Columns
• To make a cell span more than one column, use the colspan attribute:
Example
<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>55577854</td>
<td>55577855</td>
</tr>
</table>
HTML Table - Cell that Spans Many Rows
• To make a cell span more than one row, use the <td>55577854</td>
rowspan attribute: </tr>
Example <tr>
<table style="width:100%">
<tr>
<th>Name:</th>
<td>Bill Gates</td> <td>55577855</td>
</tr> </tr>
<tr> </table>
<th rowspan="2">Telephone:</th>
HTML Table - Add a Caption
• To add a caption to a table, use the <caption>
tag:
Example
<td>January</td>
<table style="width:100%">
<td>$100</td>
<caption>Monthly savings</caption>
</tr>
<tr>
<tr>
<th>Month</th>
<td>February</td>
<th>Savings</th>
<td>$50</td>
</tr>
</tr>
<tr>
</table>
HTML Table - Add a Caption
HTML Table – Add style
<table style="width:100%;"> <td>Eve</td>
<tr style="background-color:#f1f1c1;"> <td>Jackson</td>
<th>Firstname</th> <td>94</td>
<th>Lastname</th> </tr>
<th>Age</th> <tr>
</tr> <td>John</td>
<tr> <td>Doe</td>
<td>Jill</td> <td>80</td>
<td>Smith</td> </tr>
<td>50</td> </table>
</tr>
<tr style="background-color:#f1f1c1;">
HTML Table – Add style