Leveraging semantic markup alongside a CSS framework

Are there any CSS/styling frameworks out there that can work with semantic markup while keeping file sizes relatively small? It seems like a classic case of the "three options, pick two" dilemma.

Let me break it down. I want:

  1. A visual styling framework that saves me from hand-coding everything

  2. ...that is compatible with simple, semantic HTML without cluttering the code with unnecessary class names just for styling purposes. In my opinion, markup should always be minimal, straightforward, and semantic. Something like this:

    <div class="widget">
    

    ...rather than this:

    <div class="widget d-flex p-2 bd-highlight">
    
  3. ...and one that doesn't bloat file sizes too much. Frameworks are generally lightweight on their own. However, to keep them slim, they require declarative markup. Pre-processors like Sass make it easy to inherit rulesets directly from frameworks. For example:

    .widget {
        @extend .d-flex;
        @extend .p-2;
        @extend .bd-highlight;
    }
    

    But this approach can quickly result in larger file sizes due to an explosion in selector lists. Despite the tiny rulesets, the file size becomes colossal. I'm inclined to steer clear of this solution because of its impact on file size.

My instinct tells me that I have to choose between continuing to write CSS manually (giving up #1) or incorporating styles into my HTML (sacrificing #2).

Is there a way around this dilemma? Am I mishandling Sass? Are there other frameworks available that could solve this issue? While I primarily work with Sass and React, I'm open to exploring new options.

Answer №1

After extensive research on this issue, I have come to the conclusion that there is currently no effective way to integrate a CSS framework with semantic markup without experiencing significant drawbacks. As a result, I have chosen to utilize custom CSS for the final project. Here are some key points to consider:

Some frameworks (such as Bootstrap) provide styling options through mixins like @include framework-mixin(). While this can lead to duplication of rules and increase in file size, it is still lighter compared to using @extend for inheritance. However, many core classes are simply included as regular classes, raising concerns about maintaining semantic markup or facing excessive code bloat.

Most modern frameworks segment their codebase into modular components for easier customization. By carefully selecting and extending only necessary classes, you may be able to manage file sizes within reasonable limits. Instead of including the entire framework CSS file, consider including only the specific component files required for your project. Admittedly, even these files can grow quickly, but with caution and attention to detail, it is possible to make it work effectively.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it acceptable to store HTML in a content database?

I am considering storing HTML in a database, but I want to ensure it is safe. If I restrict who can submit the content, do you think it would be secure enough? My question is quite straightforward. I run a platform that provides video tutorials and variou ...

The color of the top bar remains unchanged when hovered over

I am struggling to design my personal website, and I can't seem to get the top bar to change color on hover. If you believe you have a solution, please provide your answer. index.html appears to be functioning properly, but perhaps additional adjustm ...

Step-by-step guide on replacing image and text simultaneously with a single click

I'm currently attempting to update both my text and image upon clicking (specifically on mobile), but unfortunately, I'm encountering an issue. While I've successfully managed to change the image using the function I created, the text remain ...

Change the colors of a dynamic row in an HTML table using various options

I have successfully implemented a dynamic table using HTML and JavaScript. However, instead of applying alternate row colors, I want to assign a unique color to each row. How can I achieve this? <!DOCTYPE HTML> <html> <head> ...

Content is not being contained within a div container

I'm facing a unique issue that I've never encountered before - text is not wrapping inside a div element. Here's a snippet of my HTML code: http://jsfiddle.net/NDND2/2/ <div id="calendar_container"> <div id="events_container"& ...

Version 5.1.3 of Bootstrap now combines the $colors with the $theme-colors map for enhanced customization

I am attempting to introduce some color variables like "blue", "indigo" ... to the $theme-colors map. It appears to be functioning, but after compiling, it seems duplicated in the :root selector as shown in the image below. Here's ...

Develop a distinctive JavaScript solution that enables an image to appear in fullscreen upon loading the page, and then smoothly fade away after precisely

I have been trying to incorporate a feature on my Shopify frontage website where our logo appears fullscreen and then fades away or disappears after a few seconds, allowing people to access the rest of the website. However, I am facing difficulty in making ...

Arranging content within a bounding box

Hello everyone, I'm currently working on creating a webpage layout with a main container that will house all the content. Inside this container, I have an image covering a specific portion of it, a title positioned to the left, and text to the right. ...

Ways to programmatically increase the names of variables in JavaScript?

I am currently working on developing a user-friendly recipe app with Node/Express. Users are able to access a 'new recipe' HTML form where they can easily add as many ingredients as they desire by clicking the 'add ingredient' button. U ...

What's the reason behind this file not opening?

When I try to insert this code into files index.html, style.css, and app.js, the page refuses to open. The browser constantly displays a message saying "The webpage was reloaded because a problem occurred." I am using a MacBook Air with macOS Big Sur and a ...

How to access the api variable in JavaScript

When attempting to retrieve variables from an API object, I encountered the obstacle of them being nested inside another object named "0" in this particular case. Here is a screenshot from the console: enter image description here Below is the JavaScrip ...

Is there a way to prevent text from being automatically linked after using an <a> tag?

Whenever I attempt to input text into the div tag below, it mysteriously appears hyperlinked, even though there is no "a" tag enclosing it. HTML: <html> <head> <link href = "https://fonts.googleleapis.com/css?family=Work+Sans:3 ...

Ways to Achieve the Following with JavaScript, Cascading Style Sheets, and Hypertext

Can someone help me convert this image into HTML/CSS code? I'm completely lost on how to do this and don't even know where to start searching for answers. Any assistance would be greatly appreciated. Thank you in advance. ...

My react project is experiencing erratic behavior with SCSS styling, causing inconsistency throughout the application

I've been working on customizing Material UI tables in React by applying styles to individual table cells using SCSS. I've successfully imported and applied the SCSS, which reflects correctly in my React project. However, I've noticed that e ...

You can use AJAX, JQuery, or JavaScript in PHP to upload a total of 7 files by utilizing 7 individual file input

My client has a unique request - they want to be able to upload a file in PHP without using the traditional <form> tag or a submit button. While I am familiar with file uploads in PHP, I am unsure of how to achieve this without utilizing the <for ...

Trouble with jQuery script causing initial word count issue in textarea upon page load

I have implemented a word count textarea jQuery script and I am trying to figure out how to update the word count onload to 2 when the text area initially displays "this example". Currently, it shows 0 words. Although I can set focus on it and move the c ...

Is there a way to align these images vertically on a smaller device screen?

I am attempting to arrange these images vertically on a smaller screen, displaying them in one column instead of two. https://i.sstatic.net/B0aTJ.png Below is the code I currently have: <div class="container"> <div class="ro ...

Looking to display or conceal a text box with a date picker based on the selection of a specific value from a drop-down menu

I have a dropdown with two options: Indian and Others. When I select Others, I want to display three textboxes - two with date pickers and one with a simple text input field. I have tried writing the following HTML code but I am unable to get the date pick ...

Unable to use column formatting on a row using flexbox

I am working on creating a layout with rows and columns where the content in each column is vertically aligned. Here is an example of what I am trying to achieve: Currently, I am using react and have multiple components. The approach I believe will work ...

Update the central information while keeping the entire webpage intact

Hey there, I could really use some assistance! I'm working on a software documentation website that is similar to the mongodb documentation page. It has a header, sidebar (navbar menu), and main content area. Within the sidebar navbar menu, I have dr ...