![Thumbnail](https://via.sudovanilla.org/assets/blog/stop-using-js/blog-js-dumb.png) # Stop Using JavaScript, Use These Methods Instead ## Let's Talk First, About the JavaScript Issue For years now JavaScript continues to be heavily overused for web features, where now today you have functions that have standardized, native, and high-performance equivalents in HTML and CSS. In today's modern web standards, it now allows developers to replace these complex and unnesesary scripts with simple declarative tags that provide better accessibility and speed. It's also really annoying when developers decide to use entire libraries for these basic tasks such as jQuery and React logic, which I personally hate. ### Common Overused Scenarios A lot of these scenarios have had native solutions for years now, although some are more recent than others. - Dialog Modals and Popups - Dropdown Menus - Accordions and Toggles - Tooltips - Form Validation - Scroll-down animations - Lazy Loading Images - Complex Page Transitions - Color Pickers and Complex Inputs - Responsive Element Sizing - *and much more* ### Consequences Relying so much on JavaScript for these basic functions introduces a few risks: - **Performance "Tax"**: Every 500KB of unused and redundant code can lower a site's performance score by 10 - 20 points. JavaScript can be and is *computationally* "expensive" because it must be downloaded, parsed, and executed, which clogs the browser's main thread and delays rendering time for the webpage. - **Fragility**: JavaScript is less forgiving than how HTML and CSS are. Just a single syntax error can end up breaking an entire webpage's functionality or worse, whereas browsers may often ignore minor errors in markup and styling. - **Accessibility Barriers**: Doing custom-built JavaScript components can often fail to manage keyboard focus or screen reader announcements correctly, while native elements have these behaviors "baked in". - **SEO and Maintenance**: Relying heavily on script-generated content can hinder search engine indexing. It adds layers of complexity for future maintenance compared to using standard, declarative code. ## Native Alternatives ### Dialog Modals and Popups - [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/dialog) No need to write custom scripst to handle popups, you can use the `` tag that is available natively in HTML. This dialog example with provided with a header and quick description, along with a form inside it. Forms with a submit button are able to close the dialog. A button is at the top to show a team name and an edit button that'll use `popovertarget` to show the dialog ```html

Team 2

Update Team

Change your team's name and color.

``` ### Accordions and Dropdown Menus - [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/details) I've been using the `
` tag personally to create dropdown menus for headers, elements, and more. They can also be used for accordions too. Example for a dropdown menu: ```html
Dropdown Menu
``` For an accordion menu: ```html
Question here

Answer here

Question here

Answer here

Question here

Answer here

``` Another accordion, in this one if you click any of the items, the others will close if they share the same `name`: ```html
Question here

Answer here

Question here

Answer here

Question here

Answer here

``` ## Fallbacks ### Noscript - [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/noscript) In some cases, you may need to disable or at least hide certain elements on the webpage if they require JavaScript regardless but aren't crucial. The tag `