HTML is a markup language used to create the structure of web pages. It consists of various tags that define different elements such as headings, paragraphs, images, links, and more. For example, the <h1>
tag is used for the main heading of a page, and the <p>
tag is used for paragraphs.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a sample paragraph.</p>
</body>
</html>
CSS is used to style HTML elements. It allows web developers to control the layout, colors, fonts, and other visual aspects of a web page. CSS rules consist of a selector and a declaration block. The selector targets the HTML element(s) to which the styles will be applied, and the declaration block contains one or more property - value pairs.
/* Select all h1 elements and set their color to blue */
h1 {
color: blue;
}
/* Select all p elements and set their font size to 16 pixels */
p {
font-size: 16px;
}
The <bdi>
(Bidirectional Isolate) element is an HTML5 element. It is used to isolate a part of text that might have a different text direction from its surrounding text. This is especially useful in multilingual websites where text in different languages can have different writing directions (e.g., left - to - right like English or right - to - left like Arabic).
<p>User <bdi>محمد</bdi> left a comment.</p>
To use HTML tags, you simply need to place them in the appropriate location within the HTML document. The opening tag starts with <
followed by the tag name, and the closing tag starts with </
followed by the tag name. Self - closing tags, such as <img>
and <br>
, do not require a closing tag.
<!-- Insert an image -->
<img src="image.jpg" alt="A beautiful image">
<!-- Add a line break -->
<br>
There are three main ways to apply CSS styles: inline styles, internal stylesheets, and external stylesheets.
style
attribute.<h1 style="color: red;">This is a red heading</h1>
<style>
tags in the <head>
section of an HTML document.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Internal Stylesheet Example</title>
<style>
h1 {
color: green;
}
</style>
</head>
<body>
<h1>Green Heading</h1>
</body>
</html>
.css
file and linked to the HTML document using the <link>
tag.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>External Stylesheet Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Styled by an external stylesheet</h1>
</body>
</html>
/* styles.css */
h1 {
color: purple;
}
To use the <bdi>
element, wrap the text that might have a different text direction within the <bdi>
and </bdi>
tags.
<ul>
<li>User <bdi>John</bdi>: Left a positive review.</li>
<li>User <bdi>محمد</bdi>: Left a negative review.</li>
</ul>
A well - structured HTML page typically has a <header>
, <nav>
, <main>
, <article>
, <section>
, <aside>
, and <footer>
elements. This makes the page more organized and accessible.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Structured HTML Page</title>
</head>
<body>
<header>
<h1>My Website</h1>
</header>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
<main>
<article>
<h2>Article Title</h2>
<p>Article content goes here...</p>
</article>
</main>
<footer>
<p>© 2024 My Website. All rights reserved.</p>
</footer>
</body>
</html>
For layout, CSS Flexbox and Grid are popular techniques. Flexbox is great for one - dimensional layouts, while Grid is more suitable for two - dimensional layouts.
/* Flexbox example */
.container {
display: flex;
justify-content: space-around;
}
.item {
width: 100px;
height: 100px;
background-color: yellow;
}
<div class="container">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
When dealing with multilingual content, use the <bdi>
element around names or text that might have different text directions. This ensures that the text is displayed correctly without affecting the surrounding text.
<table>
<tr>
<th>Username</th>
<th>Comment</th>
</tr>
<tr>
<td><bdi>Emily</bdi></td>
<td>Great article!</td>
</tr>
<tr>
<td><bdi>علي</bdi></td>
<td>مقال رائع!</td>
</tr>
</table>
Use semantic HTML tags like <header>
, <nav>
, <main>
, <article>
, <section>
, and <footer>
instead of using non - semantic tags like <div>
for everything. Semantic markup makes the code more readable, accessible, and SEO - friendly.
<!-- Good example using semantic tags -->
<article>
<header>
<h2>Article Title</h2>
</header>
<p>Article content...</p>
</article>
<!-- Bad example using non - semantic divs -->
<div>
<div>
<h2>Article Title</h2>
</div>
<p>Article content...</p>
</div>
em
and rem
instead of fixed pixel values for better responsiveness./* Good example: Using relative units */
body {
font-size: 16px;
}
p {
font-size: 1em; /* 16px */
}
/* Bad example: Deeply nested selector */
body div ul li a {
color: red;
}
<bdi>
when dealing with user - generated content that might have different text directions.<p>Check out <bdi>דני</bdi>'s profile.</p>
CSS, HTML, and BDI are essential components of modern web development. HTML provides the structure, CSS enhances the visual appeal, and BDI helps in handling text directionality in multilingual content. By understanding the fundamental concepts, usage methods, common practices, and best practices, web developers can create more accessible, responsive, and multilingual web pages.