Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying You Don't Need JavaScript
  • Table Of Contents Toc
You Don't Need JavaScript

You Don't Need JavaScript

By : Theo Soti
close
close
You Don't Need JavaScript

You Don't Need JavaScript

By: Theo Soti

Overview of this book

For years, JavaScript has been the default answer for almost every interactive detail on the web. Need a modal, a dropdown, dark mode, smooth scrolling, or form validation? Most frontend developers reach for JavaScript without thinking twice. But the platform has changed. This book shows how much modern HTML and CSS can already do on their own. Through practical examples, you will learn how to build real interface patterns with less code, fewer dependencies, and a stronger focus on accessibility, performance, and maintainability. You will explore features such as :has(), native dialogs, accordions, sliders, counters, dark mode, smooth scrolling, form validation, border animations, view transitions, motion paths, and mask effects. The book also introduces newer browser features like popovers, anchor positioning, scroll-driven animations, customizable selects, and CSS carousels. The goal is not to avoid JavaScript at all costs. It is to use it when it actually adds value, and not by default. By the end of the book, you will have a clearer sense of what the platform can handle today and how to build interfaces that are lighter, cleaner, and more resilient.
Table of Contents (25 chapters)
close
close
Preface
chevron up
Lock Free Chapter
1
Part 1: Everyday Features
10
Part 2: Modern CSS Power Moves
16
Part 3: A Glimpse of the Future
23
Chapter 20: Closing Thoughts
24
Index

Preface

JavaScript is powerful. No argument there. But what if much of what you're solving with JS could be handled just as well, or even better, using modern CSS and semantic HTML? This book is based on a simple principle: use the least powerful tool that gets the job done.

The Rule of Least Power

This principle originates from the philosophy behind web standards: always choose the simplest tool that effectively accomplishes the job. Start with semantic HTML to structure your content, enhance presentation and interactions with CSS, and reach for JavaScript only when absolutely necessary.

HTML and CSS are declarative languages. You describe your intent (the final look and behavior) and the browser determines the most efficient way to execute it. This approach inherently leads to simpler, more maintainable, and more accessible websites. JavaScript, however, is imperative. It demands that you explicitly define every step the browser must take, increasing complexity, performance overhead, and potential points of failure.

Why Do We Default to JavaScript?

It's easy and tempting to reach for JavaScript. Popular frameworks such as React, Vue, and Angular have made rapid prototyping and rich interactivity extremely convenient. While this convenience has significant advantages, it also often leads to bloated bundles, slower load times, and unnecessary complexity.

On the other hand, browsers have significantly evolved. Modern CSS and HTML have caught up remarkably, offering powerful capabilities once reserved solely for JavaScript. You can now implement sophisticated UI patterns such as modals, accordions, carousels, toggles, and animations purely through native browser technologies.

Why it Matters

Using minimal JavaScript translates to leaner codebases, improved accessibility, better performance, and reduced reliance on third-party libraries. Moreover, it results in decreased energy consumption, both for users and servers, significantly lowering your site's environmental footprint.

However, the aim isn't to entirely remove JavaScript. Certain tasks like real-time data fetching, complex business logic, advanced interactivity, will always benefit from JS. The goal is balance: employ JavaScript exactly where it provides genuine value, not simply because it's familiar or convenient.

By embracing a CSS-first approach, you enhance accessibility inherently. Semantic HTML and native browser behaviors are optimized for assistive technologies, supporting a broader audience by default.

Performance and Sustainability

A lighter reliance on JavaScript also means faster initial load times, reduced CPU usage, and less battery drain. For instance, substituting a JavaScript slider library (which typically weighs 50-100KB of minified JS) with a pure CSS implementation reduces overhead and significantly boosts performance.

This book invites you to pause before reaching for JavaScript. Always ask yourself first: Can CSS handle this? You'll find that the answer is "yes" more often than you'd expect, empowering you to build faster, cleaner, and more accessible websites from the start.

In the course of this book, we will cover:

  • Conditionally Styling with :has()
  • Dark Mode in CSS
  • Smooth Scrolling to Sections
  • Native Modals with <dialog>
  • Accordions with Pure CSS
  • Pure-CSS Automatic Slider
  • Auto-Numbered Headings
  • Other Use-Case of Counter
  • Custom Border Animations
  • View Transitions
  • CSS Motion Path
  • CSS Mask Effects
  • CSS-Only Form Validation
  • Scroll-Driven Animations
  • Native Popovers
  • Customized Selects
  • Anchor Positioning
  • Native CSS Carousels
  • And more to come...

This book is for people who build interfaces and want to rely less on JavaScript when they do not have to. It is aimed at front-end developers, designers who code, and curious CSS people who already know the basics and want to see how far modern HTML and CSS can really go. If you have ever added JavaScript out of habit for something the browser can already handle, this book will give you a different way to think about that.

What will you learn

  • Apply the Rule of Least Power in real UI decisions
  • Choose modern HTML and CSS over JS where it's sufficient
  • Build lightweight, accessible interfaces in practice
  • Use modern CSS features like :has(), view transitions, motion paths, masks, popovers, and anchor positioning
  • Create UI patterns like dark mode, dialogs, accordions, smooth scrolling, custom selects, and carousels
  • Implement progressive enhancement in real projects
  • Improve performance by reducing unnecessary JS

Working through this book

This is a practical book built around examples, not theory alone. It starts with familiar interface patterns, then gradually moves into more advanced CSS and newer platform features. The thread running through all of it is simple: choose the least powerful tool that can do the job well. Along the way, the book keeps coming back to the real questions that matter in front-end work, like accessibility, performance, browser support, maintainability, and how to make good trade-offs.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. For example: "Here the parent .card changes only when one of its children has the class .active."

A block of code is set as follows:

/* Targets .card only if it contains an .active element */
.card:has(.active) {
  border-color: green;
}

Warnings or important notes appear like this.

Tips and tricks appear like this.

Get in touch

Have a question, found a typo, or want to suggest an improvement? I'd love to hear from you! Email me at [email protected]

Need help with your CSS or website project? I'm available for freelance work. Let's work together, just reach out!

Want to keep learning more about modern CSS and web design? Check out theosoti.com for articles, code examples, and updates.

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book or have any general feedback, please email us at [email protected] and mention the book's title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you reported this to us. Please visit http://www.packt.com/submit-errata, click Submit Errata, and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packt.com/.

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
You Don't Need JavaScript
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon