HTML, or HyperText Markup Language, is the standard markup language for creating web pages. It uses tags to structure content on the web. For example, the <h1>
tag is used for main headings, and the <p>
tag is used for paragraphs.
<!DOCTYPE html>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to my website</h1>
<p>This is a simple paragraph.</p>
</body>
</html>
CSS, or Cascading Style Sheets, is used to style HTML elements. It allows you to control the layout, colors, fonts, and other visual aspects of a web page. CSS can be applied in three ways: inline, internal, and external.
/* External CSS example */
body {
background-color: lightblue;
}
h1 {
color: white;
text-align: center;
}
A character set (charset) is a collection of characters that a computer can use to display and manipulate text. Different character sets support different ranges of characters. For example, ASCII supports only basic Latin characters, while UTF - 8 supports a wide range of characters from different languages.
style
attribute.<p style="color: red;">This is a red paragraph.</p>
<style>
tags in the <head>
section of an HTML document.<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: yellow;
}
</style>
</head>
<body>
<p>This is a paragraph on a yellow background.</p>
</body>
</html>
.css
file and linked to the HTML document using the <link>
tag.<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>This paragraph will have styles from the external CSS file.</p>
</body>
</html>
The charset can be set using the <meta>
tag in the <head>
section of an HTML document.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Page</title>
</head>
<body>
<p>Page with UTF - 8 charset.</p>
</body>
</html>
Using external CSS files is a common practice because it allows you to reuse the same styles across multiple HTML pages. It also makes it easier to maintain and update the styles.
UTF - 8 is widely used as the default charset for web pages because it supports a large number of characters from different languages, ensuring that text is displayed correctly for a global audience.
Keep HTML for content structure, CSS for styling, and JavaScript for behavior. This separation makes the code more organized and easier to maintain.
Inline CSS makes the HTML code cluttered and harder to maintain. It also goes against the principle of separation of concerns. Instead, use internal or external CSS.
Understanding the concepts of HTML, CSS, and charset is essential for creating effective and accessible web pages. By using the proper techniques for including CSS and setting the charset, following common practices, and adhering to best practices, you can build web pages that are well - structured, visually appealing, and globally accessible.