r/css • u/Digitsbits • 9h ago
r/css • u/alexkopaleishvili • 1d ago
Question I use display: flex for almost everything. Am I missing out on something?
It's been a year since I started learning HTML, CSS, JavaScript, and web design and development in general. I build websites for my friends' small businesses, as well as personal projects.
Here's the thing: every time I want to center something, I go:
div {
display: flex;
justify-content: center;
align-items: center;
}I feel like I'm relying on Flexbox way too much. What other CSS layout techniques should I be using?
Question I created an interactive preview of 11 animated mobile navigation styles
sofmik.github.ioI built an interactive demo where you can explore different animated mobile menu styles in one place. You can switch between them right in the interface and see how they work.
Try the demo: https://sofmik.github.io/animated-mobile-navigation-demo/
There are 11 styles in the full collection, seven of which are available to try in the demo.
I also offer the full package with the HTML, CSS, and JavaScript source files. The code doesn't rely on any specific framework and can be adapted for personal or client projects, although some extra work may be needed to integrate it into an existing website.
I think it could be useful both as code to adapt for your own projects and as a way to show clients different mobile navigation options.
Would a tool like this be useful in your workflow, either for showing options to clients or as a starting point for development? Why or why not?
r/css • u/bluuupanda • 1d ago
Question how to add decorative css border to an image in an image gallery?
r/css • u/HotelWyoming • 1d ago
Help CSS background from image asset
I feel like my issue is a Programiz problem, but I thought I could get more visibility by cross posting.
r/css • u/BraveAttitude4633 • 2d ago
Question Do you prefer CSS logical properties or traditional physical properties?
I'm currently learning CSS through Kevin Powell's CSS Demystified course, and one thing the lessons strongly encourage is using logical properties instead of traditional physical properties.
For example, using margin-inline instead of margin-left and margin-right, or padding-block instead of padding-top and padding-bottom.
I understand the reasoning behind logical properties, especially when it comes to supporting different writing modes and languages. However, I personally find physical properties more intuitive since that's what I've been using for so long.
I'm curious about what other developers actually use in their day-to-day work.
Do you exclusively use logical properties?
Do you still prefer physical properties?
Do you use a combination of both?
Is it worth making the switch even if you're primarily building websites for languages that use left-to-right writing directions?
I'd like to hear your opinions and experiences, especially from developers who have been working with CSS professionally for a while.
r/css • u/fdiengdoh • 2d ago
No AI used light-dark ()
Why didn’t I know about this earlier. It’s such a nice way to achieve light/dark mode.
I just re-build my link list site using this function. Also generated color schemes at colorffy.
r/css • u/PanchuPanchu • 1d ago
No AI used Is it crucial to learn CSS nowadays or someone starting could learn tailwind directly?
r/css • u/Pertend_ • 2d ago
Help How do I get something above a fixed nav bar to be a layer above the nav bar?
I want the "Currently selected: First_select" to remain there as I scroll through the nav bar.

I've tried to use a div, but when I make it "position:fixed" it vaporizes. The only way I can think of it going under the nav bar is that I have it set to height 100%.
How I currently have it set up in the screenshot above is that I have it as a header under <nav>, but it scrolls with the nav bar which I do not want. With the div it looks like this:
Which breaks the scroll on the nav bar and breaks the text to the right.
Here is the code without the div:
<!DOCTYPE html><html lang="en">
<style>
.navbar ul{
list-style-type: none;
margin: -8px;
padding: 0;
width: 260px;
height: 100%;
position:fixed;
background-color: #313031;
text-align: center;
border: 1px solid #555555;
overflow: auto;
}.navbar a {
display: block;
color: white;
padding: 8px 16px;
font-size: 20px;
text-decoration: none;}.navbar a:hover {background-color: #545254;color: white;}
</style></head>
<body><div>
</div><nav class="navbar"><ul>
<h1 style="text-align: center;font-size: large; color: #f0f0f0; font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;">Currently Selected:</h1><h2 style="text-align: center;font-size: large; color: #67a92b;font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;text-decoration: underline;">First_select</h2>
<li style="text-align: center; border-bottom: 2px solid black; border-top: 2px solid black;background-color: #545254;"><a href="index.html">home</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="First_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Second_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Third_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Fourth_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Fith_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Sixth_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Seventh_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Eighth_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Nith_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Tenth_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Elventh_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Twelth_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Thirteenth_select.html">Misc</a></li></ul></nav>
<div style="margin-left:242px;padding:1px 16px;height:1000px;">
<article> Lorem ipsum dolor sit amet consectetur adipisicing elit. Enim sint vel impedit minima sapiente, tempore ut minus obcaecati mollitia modi quod perferendis. Perspiciatis maxime natus amet accusantium sunt labore praesentium.</article>
</body></html><!DOCTYPE html><html lang="en">
<style>
.navbar ul{
list-style-type: none;
margin: -8px;
padding: 0;
width: 260px;
height: 100%;
position:fixed;
background-color: #313031;
text-align: center;
border: 1px solid #555555;
overflow: auto;
}.navbar a {
display: block;
color: white;
padding: 8px 16px;
font-size: 20px;
text-decoration: none;}.navbar a:hover {background-color: #545254;color: white;}
</style></head>
<body><div>
</div><nav class="navbar"><ul>
<h1 style="text-align: center;font-size: large; color: #f0f0f0; font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;">Currently Selected:</h1><h2 style="text-align: center;font-size: large; color: #67a92b;font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;text-decoration: underline;">First_select</h2>
<li style="text-align: center; border-bottom: 2px solid black; border-top: 2px solid black;background-color: #545254;"><a href="index.html">home</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="First_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Second_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Third_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Fourth_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Fith_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Sixth_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Seventh_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Eighth_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Nith_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Tenth_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Elventh_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Twelth_select.html">Misc</a></li><li style="text-align: center; border-bottom: 2px solid black;"><a href="Thirteenth_select.html">Misc</a></li></ul></nav>
<div style="margin-left:242px;padding:1px 16px;height:1000px;">
<article> Lorem ipsum dolor sit amet consectetur adipisicing elit. Enim sint vel impedit minima sapiente, tempore ut minus obcaecati mollitia modi quod perferendis. Perspiciatis maxime natus amet accusantium sunt labore praesentium.</article>
</body></html>
and here it is with the div:
<!DOCTYPE html>
<html lang="en">
<style>
.Currsel{
text-align: center;
font-size: 22px;
color: #f0f0f0;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
background-color: #313031;
border: 1px solid #555555;
height: 125px;
width: 260px;
margin: -8px;
}
.navbar ul{
list-style-type: none;
margin: -8px;
padding: 0;
width: 260px;
height: 100%;
position:fixed;
background-color: #313031;
text-align: center;
border: 1px solid #555555;
overflow: auto;
}
.navbar a {
display: block;
color: white;
padding: 8px 16px;
font-size: 20px;
text-decoration: none;
}
.navbar a:hover {
background-color: #545254;
color: white;
}
</style>
</head>
<body>
<div class="Currsel">
<p>Currently Selected:</p>
<p style="color: #67a92b; text-decoration: underline;">Second_select</p>
</div>
<nav class="navbar">
<ul>
<li style="text-align: center; border-bottom: 2px solid black; border-top: 2px solid black;background-color: #545254;"><a href="index.html">home</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="First_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Second_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Third_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Fourth_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Fith_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Sixth_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Seventh_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Eighth_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Nith_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Tenth_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Elventh_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Twelth_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Thirteenth_select.html">Misc</a></li>
</ul>
</nav>
<div style="margin-left:242px;padding:1px 16px;height:1000px;">
<article>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Enim sint vel impedit minima sapiente, tempore ut minus obcaecati mollitia modi quod perferendis. Perspiciatis maxime natus amet accusantium sunt labore praesentium.
</article>
</body>
</html><!DOCTYPE html>
<html lang="en">
<style>
.Currsel{
text-align: center;
font-size: 22px;
color: #f0f0f0;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
background-color: #313031;
border: 1px solid #555555;
height: 125px;
width: 260px;
margin: -8px;
}
.navbar ul{
list-style-type: none;
margin: -8px;
padding: 0;
width: 260px;
height: 100%;
position:fixed;
background-color: #313031;
text-align: center;
border: 1px solid #555555;
overflow: auto;
}
.navbar a {
display: block;
color: white;
padding: 8px 16px;
font-size: 20px;
text-decoration: none;
}
.navbar a:hover {
background-color: #545254;
color: white;
}
</style>
</head>
<body>
<div class="Currsel">
<p>Currently Selected:</p>
<p style="color: #67a92b; text-decoration: underline;">Second_select</p>
</div>
<nav class="navbar">
<ul>
<li style="text-align: center; border-bottom: 2px solid black; border-top: 2px solid black;background-color: #545254;"><a href="index.html">home</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="First_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Second_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Third_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Fourth_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Fith_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Sixth_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Seventh_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Eighth_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Nith_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Tenth_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Elventh_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Twelth_select.html">Misc</a></li>
<li style="text-align: center; border-bottom: 2px solid black;"><a href="Thirteenth_select.html">Misc</a></li>
</ul>
</nav>
<div style="margin-left:242px;padding:1px 16px;height:1000px;">
<article>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Enim sint vel impedit minima sapiente, tempore ut minus obcaecati mollitia modi quod perferendis. Perspiciatis maxime natus amet accusantium sunt labore praesentium.
</article>
</body>
</html>I decided I was going to learn html and css like 3 days ago, so if my code is shit feel free to pick it apart.
edit: I messed up at using reddit and the first code isn't in a code block. It's in the comments though.
r/css • u/justicehwan • 2d ago
AI Assisted First npm package ever: scrollbars that don't shift your layout. Would love some feedback
Hey folks,
You know when a scrollbar pops in and everything jumps a few pixels to the left? That annoyed me enough that I made a little library for it.
One line at the root of your app, that's it:



```tsx
<MrScroll />
```
No reserved gutter, still the native scrollbar. It just finds a spot for the scrollbar so your content stays put.
- Try it: https://justicehwan.github.io/plz-mr-scroll/
- GitHub: https://github.com/justicehwan/plz-mr-scroll
It's my first library ever, so I honestly have no idea what I got wrong. If you have a minute, please take a look and tell me what's broken or dumb 🥲
P.S. I'm Korean and English isn't my first language, so sorry if anything here reads a bit off.
Thanks!
r/css • u/Asterism343 • 4d ago
Question Gradient text with solid color outline?
I'm trying to make gradient text that has an outline, and it's driving me mad. Nothing I find online works. Is there any way to do this?
Just to be clear, i want the text to have a gradient but the outline to be a solid color.
r/css • u/sweet-hypocrisy • 4d ago
Article I created a npm package to convert 2d html to 3d elements
Using only css, no threeJS or webGL, no DOM edit/manipulation. Wrap your existing html and have a 3d element.
Would love some Feedbacks and suggestions
Here is the github repo: https://github.com/Prashaxt/brickbox
Please do check it out.
r/css • u/osmium_2259 • 5d ago
Article Styling a component with inline scoped CSS
When building a demo project, I learned about CSS scoping and nesting. In particular, I learned about using the @scope at-rule in inline <style> tags, allowing you to restrict the styles to the <style> tag's parent element, whether that's a <button> or a <div>, you name it.
This, combined with nesting allowed me to style my whole component with very few class selectors, which I thought was pretty slick!
Here's a sample (Django template) from the demo:
<aside class="sidebar" tabindex="-1">
{# lines omitted for brevity #}
<div>
<style>
@scope {
ul {
margin: 0;
padding: 0;
font-size: 18px;
}
li a {
display: block;
transition: all .2s;
cursor: pointer;
border-bottom: 1px solid rgb(from var(--primary-color) r g b / 20%);
padding: 20px 16px;
}
li:last-of-type a {
border-bottom-color: transparent;
}
li a:is(.active, :hover, :focus) {
border-bottom-color: var(--primary-color);
background-color: var(--primary-color);
color: white;
}
li i {
margin-right: 8px;
}
}
</style>
<ul>
{% for name, url, icon_class, active in links %}
<li>
<a href="{{ url }}" class="{% if active %}active{% endif %}">
<i class="bi {{ icon_class }}"></i> {{ name }}
</a>
</li>
{% endfor %}
</ul>
</div>
{# lines omitted for brevity #}
</aside>For those interested, my demo is a Django project using a sidebar component to showcase the concept of creating components with Django's inclusion_tag and make the component template self-contained (e.i., HTML, CSS, JS in one file).
Curious if any of you have used inline scoped CSS like this? I'm uncertain how practical it is, but I think it is very interesting at any rate!
MDN @scoped docs: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@scope
Demo repo: https://github.com/osmium2259/django_builtin_components_demo
r/css • u/owusu_emmanuel2 • 6d ago
AI Assisted Week 1 of learning in public as a CS student: Building my first page with HTML & CSS (and finally understanding Flexbox)
Hey everyone! I'm a Computer Science student starting a "learn in public" habit to document my progress outside of regular classwork.
This week I focused on HTML and CSS fundamentals—structuring semantic tags properly and building a simple responsive layout from scratch. The biggest "aha!" moment for me was finally getting CSS Flexbox (justify-content vs. align-items) to click after spending way too long trying to center a simple card element.
Next week I'm planning to build a clean personal portfolio page to practice CSS Grid and responsive media queries.
For those who have been doing web dev for a while: what is one CSS trick or habit you wish you had learned during your very first week?
AI Assisted A customizer for my CSS library: pick what you need, get one file
I've built sites with my own CSS library, Minium, for around three years. I wanted to make it easier to customize, and to let you pick what you need. It is a minimalistic CSS library after all. So I built a customizer. You pick the parts you want, and preview the result in light and dark mode before you download one CSS file. The core is ~10KB gzipped, and everything is ~15KB.
There is no build server, because the library stores design decisions in custom properties:
Each design token is declared once in theme.css. The customizer just replaces values by name. Radius, border width, line height, flow spacing and so on.
There are seven color roles (neutral, primary, accent, success, danger, warning, info). Each role maps to a Radix color scale. You can select one of 31 color themes or build your own.
Each component lives in its own file and cascade layer, so the customizer can leave files out.
The page fetches the source CSS from the repo, applies your choices and minifies it in the browser. Extra fonts come from Fontsource on jsDelivr. And the URL holds your choices, so you can share the build as a link.
Some limitations: The library is pre-1.0 and targets current browsers, since it uses features like anchor positioning, CSS nesting and light-dark().
I wrote the CSS by hand. I used Claude to write the customizer's JavaScript.
What would you want to customize that isn't there?
r/css • u/Big-Bicycle-6347 • 7d ago
Article my css tool website css-tool.com is live now!
Hey guys, my css tool website https://www.css-tool.com is live now!
Your suggestions are highly appreciated.
It would be my honor!
r/css • u/garethheyes • 7d ago
AI Assisted Frag: A tool to steal alphanumeric/hex tokens using image backgrounds
Frag is a tool for extracting secret tokens from web pages using only CSS - no JavaScript required. It generates CSS payloads that use attribute selectors and background-image URLs to exfiltrate overlapping token fragments to an attacker-controlled server, then reconstructs the full token using De Bruijn graph traversal and Eulerian path algorithms.
r/css • u/Rafii2198 • 7d ago
Question How to properly scale images vertically in a container and preserve their right aspect ratio?
I want to write some custom CSS for a page I'm using, it has a custom CSS in its options so its really easy, but that means I can't do anything to HTML side of things, only CSS.
What I want to do is to make their media gallery wider and turn it into a carousel. Making the gallery wider also means I want to make the images there have increased height, as there is more real estate for them to fit it. The problem is that images and videos there are user submited and don't have a standardized aspect ratios or anything, everone can upload whatever they want. This is troubling me a bit as I don't know how to make it responsive, originally everything had set width and height in pixels, but I want to make it responsive, but no matter what I do, those images don't look right, sometimes they are clipped, sometimes they are massive and I was tweaking and tweaking it to the point I decided to ask for some help as nothing I do seems to work and no solution on internet helps me either, maybe I can't google who knows.
The HTML side of things basically looks like this: (The amount of content there is in card-media can very, from just 1 element to I think 50)
<div class="card">
...
<div class="card-media">
<img class="card-media-element" width="450" height="450">
<img class="card-media-element" width="450" height="253">
<img class="card-media-element" width="364" height="400">
</div>
</div>There is some already existing CSS, but it shouldn't really affect what I want, the only relevant thing that could be affecting it somehow is that card-media has position relative set and card-media-element has block-size set to auto (first time seeing this property personally, so I'm unsure what it does), but I tried to change or remove these, and nothing happened to the sizes of images. Other than that there is just text color, size, font and only stuff like that.
The CSS I wrote currently looks like this:
.card-media {
display: flex;
gap: 0.25rem;
max-width: 100%;
overflow-x: scroll;
scrollbar-width: thin;
overscroll-behavior-x: contain;
width: 100%;
height: 100%;
max-height: 26em;
padding: 0.25em;
}
.card-media-element {
object-fit: cover;
height: auto;
width: auto;
max-height: 50vh;
}The problem with this is that the images I am looking at are like zoomed in so I can't see them whole as they are like cropped, if I remove the object-fit then they are stretched, like square images become rectangular for some reason. What I want is to make all of them have the same height, and their width would be adjusted to the individual image aspect ratio. Basically I want to have consistent height of media in the card-media div, and their width can be however long it has to be, as it's overflowing anyway.
Is this possible?
r/css • u/Fraded_Panda-25 • 8d ago
Question Wow, I really want to learn CSS really well! It's something I've always struggled with, so it's tough to feel confident when I try something new. Do you have any tips on where I should focus my studies first?
r/css • u/[deleted] • 8d ago
Help Fixing a site skin that uses a different font for cursive words?
Basically, the CSS is from here: https://github.com/ao3skinsss/even-more-skins/wiki/Sakura
When I open it on my AO3 page, cursive words seem to be in Helvetica while the rest is in the standard font. How do I fix this?
r/css • u/Minimum_Hour519 • 8d ago
No AI used Introducing spatial CSS: A developer preview
r/css • u/Clear-Smoke-7356 • 8d ago
Help Help Me Find This Coding Tutorial
Soo a few years ago (prob 1) i saw a tutorial idk if it used css or js but it used it to make custom mouse cursors
Ik there are many tutorials that show the same but this one was special it had 4 cursors and all were having a feature which increased their size on clicking
To activate other cursor we just had to put our mouse on the box of that cursor
The transition between cursors was very smooth
3 of them were anime based and 1 was just a point with circle around it