Frontend
Frontend refers to the part of a website or application that users directly interact with. It includes everything users see and click, such as the layout, colors, buttons, forms, text, and images. Frontend development typically involves using HTML, CSS, and JavaScript, along with frameworks and libraries like React, Angular, or Vue.js.
Importance in IT Development:
Frontend is crucial because it provides the first impression of your website or application to users. Good frontend design ensures usability, accessibility, and responsiveness, enhancing user experience. An intuitive, visually appealing frontend can significantly impact user retention and satisfaction.
Connecting Frontend to Backend:
The frontend communicates with the backend (server-side) through APIs (Application Programming Interfaces), typically using HTTP requests (GET, POST, PUT, DELETE). This interaction allows the frontend to fetch, display, and update data managed by backend servers and databases. Together, frontend and backend form a complete system: the frontend presenting information clearly and interactively, and the backend handling the logic, storage, and business rules behind the scenes.
HTML
HTML Boilerplate
HTML boilerplate refers to a basic template or starting point for creating an HTML document. It includes the essential structure and elements required for a valid and functional HTML page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>HTML 5 Boilerplate</title>
<link rel="stylesheet" href="/style.css">
</head>
<body>
<script src="/index.js"></script>
</body>
</html>
What is a <!DOCTYPE html>
?
The <!DOCTYPE html>
declaration defines the document
type and version of HTML being used. It ensures the browser renders the
page in standards mode.
What is a <html lang="en">
?
The <html>
tag is the root element of an HTML
document. The lang="en"
attribute specifies the language of
the document as English, which helps with accessibility and SEO.
What is a <head>
?
The <head>
section contains metadata about the
document, such as its title, character encoding, and links to
stylesheets or scripts. This information is not displayed on the page.
What is a <meta>
?
The <meta>
tag provides metadata about the HTML
document, such as character encoding, viewport settings, and
compatibility information.
What is a
<meta charset="UTF-8">
?
The <meta charset="UTF-8">
tag specifies the
character encoding for the document, ensuring it supports a wide range
of characters, including special symbols.
What is a
<meta name="viewport" content="width=device-width,
initial-scale=1.0" />
?
The <meta name="viewport">
tag controls the page's
dimensions and scaling on different devices, making it responsive for
mobile and desktop screens.
What is a
<meta http-equiv="X-UA-Compatible" content="ie=edge">
?
This <meta>
tag ensures compatibility with Internet
Explorer by forcing it to use the latest rendering engine.
What is a <title>
?
The <title>
tag defines the title of the document,
which appears in the browser tab and is important for SEO.
What is a <link>
?
The <link>
tag is used to link external resources,
such as stylesheets, to the HTML document.
What is a <script>
?
The <script>
tag is used to include JavaScript files
or inline scripts that add interactivity and functionality to the page.
Nesting and Indentation
Nesting and indentation are essential practices in HTML to ensure the code is structured, readable, and easy to maintain. Proper nesting means placing elements inside their parent elements in a logical hierarchy.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example Page</title>
</head>
<body>
<div>
<p>This is a paragraph inside a div.</p>
</div>
</body>
</html>
In this example:
-
The
<html>
element is the root, and all other elements are nested inside it. -
The
<head>
and<body>
elements are direct children of<html>
. -
The
<div>
is a child of<body>
, and the<p>
is a child of<div>
.
Proper indentation (e.g., 2 or 4 spaces) makes it easier to see the relationships between elements, improving readability and debugging.
CSS
What is CSS?
CSS (Cascading Style Sheets) is a stylesheet language used to define how HTML elements are visually displayed. CSS separates content (HTML) from its presentation, simplifying design management.
<link rel="stylesheet" href="style.css">
CSS Properties
CSS properties control the appearance of HTML elements. Examples include color, font-size, margin, padding, and background.
<style>
p {
color: red;
font-size: 14px;
margin: 10px;
background-color: #eee;
}
</style>
Intermediate CSS
Intermediate CSS covers class and ID selectors, pseudo-classes, and combinators for targeted styling.
<style>
/* Class Selector */
.highlight {
color: blue;
}
/* ID Selector */
#header {
background-color: yellow;
}
/* Pseudo-class Selector */
a:hover {
color: green;
}
</style>
<div id="header">ID Selector Example</div>
<p class="highlight">Class Selector Example</p>
<a href="#">Hover over me</a>
Advanced CSS
Advanced CSS includes features such as transitions, animations, variables, and media queries for responsive design.
<style>
:root {
--main-color: purple;
}
.animated {
background-color: var(--main-color);
transition: background-color 0.5s ease-in-out;
}
.animated:hover {
background-color: pink;
}
@media (max-width: 600px) {
.animated {
background-color: yellow;
}
}
</style>
<div class="animated">Hover over me!</div>
Flexbox
Flexbox (Flexible Box Layout) is a CSS layout module used to design responsive layouts more effectively.
<style>
.flex-container {
display: flex;
justify-content: space-around;
}
.flex-item {
width: 100px;
height: 100px;
background-color: coral;
margin: 5px;
}
</style>
<div class="flex-container">
<div class="flex-item">Item 1</div>
<div class="flex-item">Item 2</div>
<div class="flex-item">Item 3</div>
</div>
Grid
CSS Grid is a powerful layout system for creating two-dimensional layouts with rows and columns.
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}
.grid-item {
background-color: teal;
color: white;
padding: 20px;
text-align: center;
}
</style>
<div class="grid-container">
<div class="grid-item">Grid Item 1</div>
<div class="grid-item">Grid Item 2</div>
<div class="grid-item">Grid Item 3</div>
</div>
Bootstrap
Bootstrap is an open-source CSS framework used to create responsive, mobile-first websites. It includes ready-to-use components, a 12-column grid system, utility classes, and responsive design features.
Include Bootstrap via CDN:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
Basic layout using container, row, and columns:
<div class="container">
<div class="row">
<div class="col-md-4">Column 1</div>
<div class="col-md-4">Column 2</div>
<div class="col-md-4">Column 3</div>
</div>
</div>
Example using cards:
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card 1</h5>
<p class="card-text">Some example content.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card 2</h5>
<p class="card-text">Some example content.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Card 3</h5>
<p class="card-text">Some example content.</p>
</div>
</div>
</div>
</div>
Bootstrap helps streamline design, promotes responsive practices, and reduces the amount of custom CSS you need to write.
JavaScript
JavaScript is a programming language used to add interactivity and dynamic behavior to websites. It runs in the browser and allows developers to respond to user actions, manipulate HTML elements, and communicate with backend services.
Including JavaScript in an HTML document:
<script src="script.js"></script>
Writing JavaScript directly in the HTML file:
<script>
console.log("Hello from JavaScript");
</script>
Changing text content of an element with JavaScript:
<div id="message">Original Text</div>
<script>
document.getElementById("message").textContent = "Updated Text";
</script>
Handling a button click event:
<button onclick="showMessage()">Click Me</button>
<div id="output"></div>
<script>
function showMessage() {
document.getElementById("output").textContent = "Button clicked!";
}
</script>
JavaScript can fetch data from a backend using the
fetch()
function.
<script>
fetch("https://api.example.com/data")
.then(response => response.json())
.then(data => console.log(data));
</script>
JavaScript is essential for modern web development. It powers features like form validation, dropdowns, sliders, AJAX requests, and much more.