HTML is a markup language used to create the structure of a web page. It consists of elements, which are represented by tags. For example, the <html>
tag is the root element of an HTML document, and it contains other elements like <head>
and <body>
.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF - 8">
<title>My Web Page</title>
</head>
<body>
<h1>Welcome to my web page!</h1>
<p>This is a simple paragraph.</p>
</body>
</html>
CSS is used to style HTML elements. It uses selectors to target HTML elements and declarations to define how those elements should look. A CSS rule consists of a selector and a set of declarations enclosed in curly braces.
h1 {
color: blue;
font - size: 24px;
}
A CSS bin is an online tool or an environment where developers can write and test CSS code without having to set up a full - fledged development environment. It usually provides a split - screen view with an area for HTML code, CSS code, and a preview area to see the results in real - time. Popular CSS bins include CodePen, JSFiddle, and JS Bin.
To write HTML, you can use a simple text editor like Notepad (on Windows) or TextEdit (on Mac). Start by creating a new file with a .html
extension. Then, use HTML tags to structure your content. For example, to create a list:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
There are three ways to apply CSS to an HTML document:
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 lang="en">
<head>
<meta charset="UTF - 8">
<title>Internal CSS Example</title>
<style>
p {
color: green;
}
</style>
</head>
<body>
<p>This is a green paragraph.</p>
</body>
</html>
.css
file and link it to your HTML document using the <link>
tag in the <head>
section.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF - 8">
<title>External CSS Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>This paragraph's style is defined in an external CSS file.</p>
</body>
</html>
In the styles.css
file:
p {
color: purple;
}
Let’s take CodePen as an example.
Semantic HTML means using HTML tags that convey the meaning of the content. For example, instead of using a <div>
for every section, use tags like <header>
, <nav>
, <main>
, <article>
, <section>
, and <footer>
.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF - 8">
<title>Semantic HTML Example</title>
</head>
<body>
<header>
<h1>My Website</h1>
</header>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<main>
<article>
<h2>Article Title</h2>
<p>Article content goes here...</p>
</article>
</main>
<footer>
<p>© 2024 My Website</p>
</footer>
</body>
</html>
CSS selectors are used to target specific HTML elements. Common selectors include:
p {
font - style: italic;
}
<p class="highlight">This paragraph will be highlighted.</p>
.highlight {
background - color: yellow;
}
<p id="unique - paragraph">This is a unique paragraph.</p>
#unique - paragraph {
color: orange;
}
Responsive design ensures that a web page looks and functions well on different devices and screen sizes. You can use media queries in CSS to apply different styles based on the screen width.
/* For mobile devices */
@media (max - width: 767px) {
body {
font - size: 14px;
}
}
/* For tablets */
@media (min - width: 768px) and (max - width: 991px) {
body {
font - size: 16px;
}
}
/* For desktops */
@media (min - width: 992px) {
body {
font - size: 18px;
}
}
/* This is a comment explaining the following CSS rules */
h2 {
margin - bottom: 10px;
}
border - radius
may need -webkit - border - radius
for Safari and Chrome, and -moz - border - radius
for Firefox..box {
-webkit - border - radius: 5px;
-moz - border - radius: 5px;
border - radius: 5px;
}
CSS, HTML, and CSS bins are essential tools in web development. Understanding the fundamental concepts, usage methods, common practices, and best practices will help you create more professional, efficient, and user - friendly web pages. Whether you are a beginner or an experienced developer, using CSS bins can significantly speed up your development process and allow you to experiment with new ideas.