01. Styling Basics Including JavaScript
Introduction
Section titled “Introduction”HTML provides the structure, CSS handles styling, and JavaScript adds interactivity. Understanding how these three technologies work together is fundamental to web development. While HTML can include basic styling and JavaScript, best practices involve separating concerns and using each technology for its intended purpose.
HTML Structure
Section titled “HTML Structure”HTML provides the foundation:
<div class="container"> <h1>Title</h1> <p>Content</p></div>CSS Styling
Section titled “CSS Styling”CSS styles the HTML:
<style> .container { background-color: #f0f0f0; padding: 20px; } h1 { color: #333; }</style>JavaScript Interactivity
Section titled “JavaScript Interactivity”JavaScript adds behavior:
<script> document.querySelector('.container').addEventListener('click', function() { this.style.backgroundColor = '#ccc'; });</script>Integration Methods
Section titled “Integration Methods”Inline Styles
Section titled “Inline Styles”<div style="color: red; font-size: 18px;">Styled content</div>Internal CSS
Section titled “Internal CSS”<style> .class { color: red; }</style>External CSS
Section titled “External CSS”<link rel="stylesheet" href="styles.css">Internal JavaScript
Section titled “Internal JavaScript”<script> // JavaScript code</script>External JavaScript
Section titled “External JavaScript”<script src="script.js"></script>Best Practices
Section titled “Best Practices”Separation of Concerns
Section titled “Separation of Concerns”- HTML: Structure and content
- CSS: Visual presentation
- JavaScript: Behavior and interactivity
External Files
Section titled “External Files”Prefer external files:
<link rel="stylesheet" href="styles.css"><script src="script.js"></script>