![]() |
![]() |
![]() |
![]() |
![]() ⇓ |
![]() |
![]() |
---|
So far, we have only used images by linking to them from other websites (e.g., using a full
https://...
URL). But this raises a fundamental question:
Imagine you are in Dwarka, Delhi, and need to give someone directions to Chandni Chowk. You have two ways to do it:
This same logic applies to files in our project:
/
).
cow.jpg
from inside the beta
folder, the
path is beta/cow.jpg
.../
). This moves
you to the parent directory.
cat.png
which is one level above the current file, the
path is ../cat.png
../
). While simply writing the filename (dog.jpg
) works, explicitly
writing ./dog.jpg
is a clearer, recommended practice that signifies the file is in the
same directory.https://some-website.com/image.jpg
is an
absolute path.C:/Users/YourName/image.jpg
on Windows or /Users/YourName/image.jpg
on
macOS/Linux.
<img src="C:/Users/YourName/private-photo.jpg">
), what could go wrong?../
) to navigate outside of your project's root folder. The browser creates a
"sandbox" to protect your computer.We've seen that writing <h1>Hello</h1>
in a file works. So why do we need all the extra
"boilerplate" code that professional developers use?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- Your content goes here -->
</body>
</html>
<!DOCTYPE html>
: This is the very first line and it declares that the
document is an HTML5 document.<html lang="en">
: This is the root element that wraps everything. The
lang="en"
attribute specifies that the page's primary language is English, which is important
for accessibility and SEO.
<head>
: This section contains meta-information about the page. The
content here is not displayed in the main browser window.
<meta charset="UTF-8">
: This is crucial. Computers only
understand numbers (specifically, binary). This tag specifies the character encoding standard
(UTF-8) that maps every character, symbol, and emoji from every language in the
world to a unique number, allowing the browser to store and display it correctly.<meta name="viewport"...>
: This tag is essential for responsive
design. It tells the browser to set the page width to the screen width of the device it's being
viewed on (like a phone or tablet), ensuring the content scales correctly.<title>
: This sets the text that appears in the browser tab,
helping users identify the page.<body>
: This section contains all the visible content
of your webpage, like headings, paragraphs, images, and links.As pages get more complex, we run into new problems: How do we apply one style to a whole group of elements? And how do we target one very specific element and nothing else?
<div>
(The Container)<div>
tag. It's an invisible
container used purely for grouping other elements. By applying a style (like
text-align: center
) to the <div>
, you apply it to everything inside,
saving you from styling each element individually.
class
Attribute (The Grouping Label)<div>
?
class
attribute. You can assign the
same class name to multiple, separate elements. This creates a "group" that can be targeted with
CSS. Class names are reusable and can be applied to many elements.id
Attribute (The Unique Identifier)id
attribute. An ID must be
completely unique on the entire page. No two elements can have the same ID. It is
used to pinpoint a single element, often for manipulation with JavaScript.
Sources: Internet. All copyrights © reserved #DarkProgrammer, Let's connect.