What do you wish CSS could do natively that it canāt do now? First, letās review the last time we did this in 2013.
- ā āIād like to be able to select an element based on if it contains another particular selectorā
- ā āIād like to be able to select an element based on the content it containsā
- ā āIād like multiple pseudo elementsā
- ā āIād like to be able to animate/transition something to
height: auto;
ā - ā āIād like things from Sass, like
@extend
,@mixin
, and nestingā - ā āIād like
::nth-letter
,::nth-word
, etcā - ā āIād like all the major browsers to auto-updateā
Ouch. Oh well. Iām not sure how hotly requested all those actually are or how feasible it is to even implement them. Theyāre merely ideas that I thought we be useful in 2013, and as it turns out, I still do.
This time, instead of me making my own list, letās have a gander around the internet at other people who have rounded up CSS desires.
TL;DR List
In observing several sources of conversation around things people desire in CSS, these seem like the most common asks:
- Parent queries. As in, selecting an element any-which-way, then selecting the parent of that element. We have some proof itās possible with
:focus-within
. - Container queries. Select a particular element when the element itself is under certain conditions.
- Standardized styling of form elements.
- Has/Contains Selectors.
- Transitions to
auto
dimensions. - Fixed up handling of viewport units.
Notably, whatās interesting to me is the lack of people asking for style scoping. It came up a little, but not a ton. It seems like such a big part of the CSS-in-JS conversation, so Iām surprised to see so little mention of it in the context of general āwhat does CSS need?ā conversations.
Jen Simmons asked whatās on our lists
Making a wish list of all the things Iād love to see happen in the world of CSS in 2019. Whatās on your list? Things you want to learn? Problems you want help solving? New properties you need? Design ideas you wish you could code? Resources youād love to have? Name your desire.
— Jen Simmons (@jensimmons) November 14, 2018
Notable replies from the thread:
- Aspect ratios (itās weirdly tricky in CSS, coming to HTML probably, and maybe weāll get it natively in CSS with a property someday)
- Exclusions
- Regions
- Subgrid (itās coming!)
text-wrap: avoid-widows-and-orphans
- Nesting
- Outline with radius
- Animated background gradients (without faking it by moving them or whatever else)
text-overflow:ellipsis
over multiple lines / line clamping- 0-to-auto transitions
- Parent selectors
- Async
@import
- Math functions like
sqrt()
,sin()
andcos()
font-min-size
andfont-max-size
- Masonry
Tab Atkins wanted to know what parts of CSS give us the most trouble
What parts of CSS give you the most trouble due to browser behavior differences? Collecting some data, please RT. (If answer is different for mobile vs desktop, let me know.)
— šTaudry Hepburnš (@tabatkins) October 3, 2018
Notable replies from the thread:
- Tons and tons of requests for a standardized way to style form elements — not just for styling desire, but for accessibility to prevent trading standards for styling.
- Being able to test browser support of more than just property/values with
@supports
- Improved handling of viewport units and their relationship to other browser UI
- Improved handling of multi-column layout handling
- Elastic scrolling
Tommy Hodgins did a CSS+JS advent calendar on Twitter that documents interesting possibilities
Dec 1: Parent Selector šš Though CSS doesn't have a :parent selector, you can create your own with a small JavaScript function and use a selector like [āparent] in your CSS stylesheets today!
demo: https://t.co/9N1A1Un8XT
code: https://t.co/NNUuvOi1zH#css #javascript pic.twitter.com/Nv8V3rl2AF— Tommy Hodgins (@innovati) December 1, 2018
Tommyās list:
- Parent selector
- Has selector
- Closest selector
- First in document (like how
querySelector
works) - Elder sibling selector
- Previous sibling selector
- Contains selector
- Regex selector
- Computed style selector
:nth-letter
/:nth-word
- Media pseudo selectors
- Not-blank valid/invalid selector
- Element queries
- Attribute comparison selectors
- Custom specificity
- Visibility selectors
- Overflow detection selector
- User agent detection selector
- Storage queries
- Date queries
- Protocol queries
- Deep hover
We asked as well
Putting together a list of most-wanted native CSS features. There are lots of ideas out there!
Hit me with quick hit ideas. Don't think too hard.
— CSS-Tricks (@css) December 17, 2018
Notable replies from the thread:
- Container queries
- Has selector
- Regions
- Color modification functions
- Nesting
- Shaders
- Transition to
auto
dimensions / transition fromdisplay: none;
- Previous sibling selector
font-size: fit;
- Styling
grid-template-areas
- Animation between
grid-template-areas
- Types for custom properties
clip-path
accepting pathsinline-styles: ignore;
- Aspect ratios
- Scoping
// single line comments
- Corner shapes
Maybe not completely on topic, but thereās one thing i really would like regarding CSS. I wish there was a way to make visible which CSS rules are never used. Something like a log file which can be switched on and off and lists all selectors that are not used or are always overridden on a given HTML page. I do not know if something like this is possible but it would be very nice to have. Just to clean up the CSS. Iāve never found something like this or any requests for it.
This isnāt as powerful as your comment suggests, but have you seen the coverage tab in chrome dev tools?
Saw this article today:
https://umaar.com/dev-tips/121-css-coverage/
Or:
https://www.vojtechruzicka.com/measuring-javascript-and-css-coverage-with-google-chrome-developer-tools/
What about: Media queries based on viewport orientation (portrait / landscape)
Or is this already possible?
It is! Itās been possible for more than half a decade. Demo.
This is currently possible! More info here.
A very useful feature!
I wish for a simple
text-align: center center;
for centering horizontal and vertical.
In the year 2019 we still have to use weird hacks or illogical div-nesting.
This is a layout issue, not a text alignment one. And itās not a one-liner, but flexbox accomplishes this very easily.
If you know the height of the container that holds the text and the text is on only one line, itās very easy to do this. Set line height to that of the elementās height.
Granted thatās a very specific use case and doesnāt cover most cases. If you donāt know container height and/or the text is multiple lines, you can use
position: relative; top: 50%; transform: translateY(-50%);
.See my demo which shows both methods. I do agree that
text-align: center center
would be nice. Though it would require modifying an existing rule to become shorthand. Instead oftext-align
we would needtext-align-vertical
andtext-align-horizontal
, and simplytext-align
would become the shorthand, and if passed only one value would it apply it to both?text-align: center
would be the same astext-align: center center
? That would be problematic. Because if you didtext-align: left
would that try to apply āleftā totext-align-vertical
?The idea is good but Iām not sure how it would be executed.
I think that if the same things are requested many times from many people and since 2013ā¦ maybe W3 should ask itsself if āare we going to meet developer needs?ā and re-consider some opinionsā¦
Personally I surely would like to have parent selectors and container queries.. above all
Some proposals have huge challenges, take container queries for example, such feature could easily trigger an infinite loop of repaint, if two elements react to changes in a way that triggers the other element to change and so on, like parent and child or two siblings.
Then the parent selector, which I could not find an official proposal, but most articles suggest a syntax with
<
or:parent
. Itās not simple to introduce something like that, imagine the following:a < img
to select anchors that have an image child, but then someone writes this:a < img + span
ora < img > span
, it could be maddening, itās even going against the ācascadeā part of CSS.Parent selectors are very high on my list, something like:
Animating gradients without resorting to
background-position
orbackground-size
. Weāve had this in IE10+ and Edge for more than half a decade, but nobody ever seemed to notice and now itās going to get all dropped anyway.Oh, well, itās not like Chrome doesnāt now have something even better ā the ability to animate CSS variables, which means we can animate different components of a gradient differently.
For example, letās consider the following gradient:
Here we can have a different animation (different set of keyframes, different duration, different timing function, different delay) for each CSS variable, whereas animating the gradient itself (as it is possible in Edge today) means animating everything the same way.
Of course, itās still all behind a flag (Experimental Web Platform features from
chrome://flags
) thatās apparently hard to find judging by how often Iām told my Houdini demos donāt work. For anyone wanting to know more, I wrote an article on it right here.clip-path: path()
. Itās already been implemented in Firefox. Quietly, without saying a word about it. It needs thelayout.css.clip-path-path.enabled
set totrue
inabout:config
in order to work.My honest opinion? Meh. And hereās why: the value in the
path()
is a string value that, just like the value of thed
attribute of an SVG path, only accepts unitless values. What do these values translate to in CSS? Pixels! So the coordinates used for this path are always pixel coordinates relative to the top left of the clipped element. Hereās a test. Needs to be opened in Firefox with the flag mentioned above set totrue
.Want anything responsive this way? Sorry, nope. Better option at this point is to use a child SVG and modify its
d
from the CSS. Only works in Chrome and doesnāt reflect the latest spec changes, but at least itās responsive! Basic example and something a bit more interesting.Useful mathematical functions like
floor()
,abs()
,pow()
, trigonometric functions. This is one I personally hit the need for a lot. Off the top of my head, some use cases:Modulo. I may have a bunch of similar items that letās I say position on a circle (think something of the kind). This is done by setting an index custom property
--i
on each of them and another custom property--n
representing the total number of items on their parent and then setting the itemtransform
torotate(calc(var(--i)*1turn/var(--n))) translate($r)
. And now letās say I want to make every other item black. Currently, I can do this with something like:nth-child(odd) { background: black }
, but, if I could use modulo, I could set thebackground
only once (!!!) withbackground: hsl(348, 83%, calc((var(--i)%2)*47%))
. Demo.abs()
. Starting from the same example of items distributed on a circle, letās say I want to have theiropacity
increase linearly for the first half of the circle and then decrease linearly for the second half. Withabs()
, we could haveopacity: calc(1 - abs(2*(var(--i) - .5*var(--n))/var(--n)))
, but now we have to change the sign for half the elements and that means hardcoding the number of elements in a selector like:nth-of-type(-n + 6)
.pow()
. Letās say I want to have a secondary rotation. Or letās say I want to have a cubic increase in theheight
of items.Trigonometric functions. My primary use case is for syncing rotation angles and scale factors or translation distances when I animate multiple elements such that corners/ edges match throughout the animation. In this demo, I need to sync the rotation angle of the bright yellow squares and the post-skew scale factor of the orange squares. This is achieved by doing the trigonometric computations in the JS and then setting the values to the custom properties used in the
transform
. I could also try to fake it with different timing functions for rotation angles and scale factors or translation distances as I did in this demo, but thatās just hardcoding thecubic-bezier()
for every case.I think āCascadeā style sheet, has a big problem with the āCascadeā concept.
i.e:
why not write on āCascadeā?. Something like this:
Pros:
* you really see the cascade in one place.
* its easy to change and debug
* its more compact, reducing the file size
Itās already possible with preprocessors like SASS, but itād be nice to have it natively on plain CSS.
Leading in the web, leading in the web!!! :)
Enough with
line-height
, it is seriously terrible.Leading would allow for vertical rhythm (if you want it), and more importantly to be able to match print to web or web to print more seamlessly (or the whole gamut print to web to print).
I worked hard to find a way to create leading in the web, but it shouldnāt have been hard to do. (https://github.com/shalanah/baseline).
Also, shout-out to having consistent white-space wrapping for text cross browsers.
Is the āprevious sibling selectorā the opposite of the āadjacent sibling combinatorā?
If yes, I put all my coins into that one!
CSS blending modes (like multiply, hue, and overlay) becoming mainstream & supported would make things so much better for designers looking to push the visual envelope.
Aspect ratios are probably coming too. Thereās a draft, at least:
https://drafts.csswg.org/css-sizing-4/#ratios
I would like to have something to check if element is in sticky position. For example
:sticky
selector.