Problem with Linear Gradient in Safari

Hey guys, i’m having problems with a linear gradient not showing up on safari (desktop). it’s showing fine on chrome though:

you can see it at climate-tech dot net

the CSS i’m using is:

#rt-top-surround { background-color: #F1F1F1; background-image: linear-gradient(to bottom, #FFFFFF, #DDDDDD); background-repeat: repeat-x; border-bottom: 1px solid #FFFFFF; box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.298); color: #6E6E6E; text-shadow: 0px 2px 3px #FFFFFF; }

in Safari when i inspect the element, the “background-image” line has a warning icon by it but doesn’t tell me what’s going on with it.

What version of safari and what O/S are you using, please?

Mac has 9.0.3 Win7 has 5.1.7

it’s happening on both.

What does the HTML look like that the CSS styles? and is any of the surrounding HTML/CSS relevent to the issue?

Could you post the code that demonstrates the issue in a “working page” so we can test exactly what you have written.

Not that I can tell. It’s strange because other browsers don’t have an issue.

I do not have Safari on my PC, so we will need a Safari person to pick up this topic, please.

Have you tried

without the background-repeat?

It doesn’t seem to make a difference with that.

You can check it out here: climate-tech.net

On my mac version of safari (9.x) it seems fine. but on the windows one (5.x). The windows one is having the issue consistently

Didn’t Apple abandon Safari on windows about four or five years ago because no one was using it?

It probably isn’t worth worrying about long abandoned browsers not working properly - there are probably more people still using Netscape 4 rather than Safari 5 on Windows computers.

That sounds like an improvement. Safari on Windows is no longer supported and it’s 4 years out of date. Do you need to support it?

Did you try the -webkit prefix?

:frowning:

I’ll see if i can get him to come into the office since he’s local and show me what he’s seeing.

Thanks everyone!

This will be what he’s seeing…

safari css gradient problem

Yeah I see that too, but getting him in here with his equipment will allow me to explain the problems with out of date versions and update his software. Hopefully that’ll take care of it.

There probably is no more recent version of Safari because Apple abandoned it - so you’ll need to decide which browser to swap him to.

You can add an image gradient before the css gradient as a fall-back for old browsers if you need to support them. But Safari for Windows is a dead browser, one that no one should waste time trying to cater for. The client needs to get a modern browser, Chrome, Firefox, Edge, anything will be better than that.

Safari for Windows is an old browser, if you want to get rid of it then get a modern browser like Chrome, Firefox, Edge, anything will be better than that.

As others have said safari on the PC is dead and should not be used because apart from the fact that is its a very old and dead browser and will support little css3 it will also be a security issue because it is not maintained. Users should remove it from their system as it has no viable use these days.

Notwithstanding the above the problem with your code is that safari 5.1 on the PC doesn’t understand the new linear gradient syntax (because it wasn’t around then) and you would need to use the prefixed version.

The above is tested and working in safari PC (I have it installed an an old machine that I don’t use anymore).

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.

Safari bug with gradients that fade to "transparent"

Say you have a gradient in CSS that goes from red to transparent. Easy, right? Like this:

Code language: CSS

There is a pretty big gotcha here, though. In Chrome (also Android), Firefox, and Edge, you’d be all good.

A side by side comparison of Chrome, Edge, and Firefox, all displaying the same test page containing two rectangles, which have a gradient background that starts red at the top and fades to transparent at the bottom of each rectangle.

But in Safari (also iOS), you’d not be good.

The same test page as before, viewed in both the iOS simulator version of Safari, and the macOS version of Safari. The two rectangles, each with a gradient background colour are different this time. The red in the rectangle on the left fades from red to black, as it fades to transparent, which appears to be a bug. The rectangle on the right fades to transparent while still maintaining the red colour, as expected.

Fixing Gradient Banding in Software Development: A Guide for Chrome and Safari

Abstract: This article provides a solution for gradient banding issues that occur in Chrome and Safari when coding linear radial gradients. Learn how to fix this problem and improve your web development skills.

Gradients are a common feature in web development, and they can be used to add visual interest and depth to a website. However, gradient banding can be a frustrating issue that can detract from the overall look and feel of a website. This issue is particularly prevalent in Chrome and Safari, and can be caused by a number of factors. In this article, we will explore the causes of gradient banding, and discuss some potential solutions for fixing this issue in Chrome and Safari.

What is Gradient Banding?

Gradient banding is a visual artifact that can occur when displaying gradients on a digital display. It is characterized by visible bands of color that can detract from the smooth gradient that was intended. This issue is particularly noticeable on high-resolution displays, and can be caused by a number of factors, including limitations in the display hardware, limitations in the web browser, and limitations in the gradient generation algorithm used by the web developer.

Causes of Gradient Banding in Chrome and Safari

There are several causes of gradient banding in Chrome and Safari. One common cause is limitations in the display hardware. Some displays are not capable of displaying a true gradient, and instead approximate the gradient using a series of discrete color values. This can result in visible banding, particularly on high-resolution displays.

Another common cause of gradient banding in Chrome and Safari is limitations in the web browser itself. Both Chrome and Safari use a gradient generation algorithm that can result in visible banding on some displays. This issue is particularly prevalent on high-resolution displays, and can be exacerbated by other factors, such as the use of dithering or the use of a low-quality gradient generation algorithm.

Solutions for Fixing Gradient Banding in Chrome and Safari

There are several potential solutions for fixing gradient banding in Chrome and Safari. One solution is to use a higher-quality gradient generation algorithm. This can help to reduce the visibility of banding on some displays, and can result in a smoother, more visually appealing gradient.

Another solution is to use dithering to help blend the colors in the gradient. Dithering is a technique that is used to create the illusion of a smooth gradient by using a pattern of small dots or pixels. This can help to reduce the visibility of banding on some displays, and can result in a more visually appealing gradient.

A third solution is to use a higher-quality display. Some displays are better at displaying gradients than others, and using a higher-quality display can help to reduce the visibility of banding on some displays.

Gradient banding can be a frustrating issue for web developers, particularly in Chrome and Safari. However, there are several potential solutions for fixing this issue, including using a higher-quality gradient generation algorithm, using dithering, and using a higher-quality display. By implementing these solutions, web developers can help to reduce the visibility of banding on some displays, and can create a more visually appealing gradient.

  • Gradient banding is a visual artifact that can occur when displaying gradients on a digital display.
  • Gradient banding is particularly prevalent in Chrome and Safari, and can be caused by limitations in the display hardware, limitations in the web browser, and limitations in the gradient generation algorithm used by the web developer.
  • There are several potential solutions for fixing gradient banding in Chrome and Safari, including using a higher-quality gradient generation algorithm, using dithering, and using a higher-quality display.
  • Smoother Gradients with CSS Linear Gradients
  • Gradient Banding and How to Avoid It
  • Linear Gradients

Tags: :  software development gradient banding Chrome Safari

Latest news

  • Linear Model for Diabetes Prediction: Factor Variables in R
  • Routing Issues in PHP XAMPP Local Machine for a New Developer
  • Creating Series of Buttons for a File Folder on Server-side with Java Script
  • Deleting Cell Formulas in C# OpenXML Excel 2013
  • Fifth Night: Solving Scaling Issues with Raster Paper.js using Drag
  • Modifying Custom Layout HTML Parent Properties in DataTables 2.0
  • Cross-Validation of Multivariate Time Series Model using LightGBM in MLexperiments with mlrRS
  • Understanding Page Width with KnowingSize PageFlet
  • Setting up Proxy in Quasar.config.js for Axios requests on different server ports
  • Unhandled Exception: Unable to Load Asset: 'assets/asset/sound/beep.mp3'
  • Configuring PingFederate SSO with React Frontend and Django Backend (Python) for SAML Authentication
  • Error 'Blob Already Exists' When Exporting Azure Database BACPAC Container
  • Boosting Speed: Python Function with Numpy Array Input
  • Memory Leaks in Large C++ Programs: Identifying Objects Not Destroyed
  • PHP Doesn't Read Cookies Set with JavaScript
  • Angular 17 SSR with QuillJS: 'document not defined'
  • Querying Single-Table DynamoDB Child Objects: A Practical Approach
  • Understanding Rigid Type Binding in Haskell: A Deep Dive
  • ServerSentErrorHandling in Godot Game Engine with Laravel Backend
  • MTA Account Char Limits: Permissions for Character Creation
  • Installing Ora2pg on Windows Server 2019 with Strawberry Perl and DBD-Oracle
  • Understanding Exception Handling in Blazor Server (.NET 7) _Layout.cshtml and the display of Unhandled Exception Bubbles
  • Why Don't Conditional For Loops Work with Loops in JavaScript?
  • Automating Open Source Tools Installation: Editing Text Files with User Input
  • Getting Google ReCAPTCHA V3 to Work in a Single Form ASP.NET MVC3 Project
  • Cannot Upload PDFs using PHP (MAC): A Solution
  • Managing Access Secrets for Different Project Builds in Google Cloud Build
  • Checking Active Database Sessions with Auth Context in Stack Router
  • Changing Multiple Level Column Names in Pandas to One Level
  • Creating an Android TV Launcher App: A Similar Experience to Projectivity Launcher
  • Restricting Anonymous Access to Specific Views in View(V1) using Role-Based Access Control
  • Issue with Typewriter-Effect Animation in React App: Cursor Not Hidden
  • Plotly Heatmap: Center, Zoomed Zone, and Zooming Rectangle
  • Updating Home Screen in React Native using StackNavigator: A Step-by-Step Guide
  • Avoiding Duplicate Target Files in Informatica: Disabling File Creation

Multi-line Gradient Text Safari / iOS Fix (i.e., prevent disappearing text)

Why post in Design Help: Webflow should add the correct webkit prefixed CSS attribute into their default CSS engine so this bug is fixed for all Webflow users. Likewise important because Webflow Designer Preview may give you false confidence (as does any UA/viewport-based previewing). The bug is Safari’s rendering (e.g., requires a live device).

Three weeks ago, Webflow added the CSS background-clip feature live to all users.

On Safari / iOS, multi-line gradient texts and backgrounds in parent divs do not work well with position: inline . This bug has been documented , but seemingly only in the annals of CSS Quirks Volume 54.

I’ve lost some sleep this past week in finding a fix. Nobody else should need to suffer, as this bug requires a webkit-specific-prefix that is rather rare.

The layout is simple, but Safari can’t handle this situation.

Wrapper div: background: white, position: inline Gradient text div: gradient clip to text, position: inline

Webflow-Wrong-Gradient-Webkit-Prefix

What is the fix? On the div containing the gradient text,

It solved my problem! Thanks a lot for sharing this =D

I signed up for a forum account just to say thanks. This was driving me insane. Cheers.

THANK YOU! This helped a lot!

@magicmark , would you know if this “quirk” / “bug” could either be 1) noted in Webflow’s documentation or 2) a temporary fix added to Webflow’s default CSS engine?

I don’t know how much else would break, but I do note the workaround is prefixed.

Or does Webflow expect Safari to handle this, while Webflow users need to find this specific forum post and/or read Zell’s blog?

Thanks for sharing TG2. Like others mentioned this issue was driving my crazy.

THANK YOU! I can’t tell you how long I have been trying to fix this problem. I was about to give up and remove gradient text from the site, so this made my day!!

Could you please help me to define where that html should be posted?

Ditto to @Philein ’s question, does anyone know where to place the code?

Which div does this code go? On the text span? or the text content? or a parent div?

And where does it get placed? In the custom attributes section?

Hello, everyone! My apologies. Webflow Forum notifications were in spam: wonder how that happened.

This code is applied to the gradient text div, so whichever div is the gradient text.

Where to put the code: three spots.

  • Per page: this can go into the “before the </body> tag” in Page Settings
  • Per page: this can also go into a custom embed block (make sure you keep the tags)
  • Per-site: Head to your site settings, Custom Code, and drop it into Footer Code

It is not critical (e.g,. just CSS) so the <head> box isn’t appropriate. Unfortunately, we are no longer actively maintaining our Webflow site, so I haven’t had much chance to see if this has been fixed or not, or if there’s a better way, but it is still functioning on the client’s old Webflow site.

Safari Gradient Animation Issue

Gradient Animation Not Working in Safari: A Solution

Abstract: This article discusses a common issue with gradient animations not working in Safari and provides a potential solution.

Gradient Animation Not Working in Safari: Solution

Gradient animations are a popular way to add visual interest to websites. However, if you've tried to use a gradient animation and found that it doesn't work in Safari, you're not alone. In this article, we'll explore the reasons why gradient animations might not work in Safari and provide a solution to get them up and running.

Understanding the Problem

The issue with gradient animations in Safari is related to the way that the browser handles the animation and transform properties. Specifically, Safari has a bug that causes these properties to not work correctly with linear gradients that have an angle value specified.

To see this in action, check out the following example:

This code creates a simple gradient animation that moves the gradient back and forth. It works perfectly in Chrome and Firefox, but in Safari, the animation doesn't move at all.

The Solution

The solution to this problem is to use a workaround that involves creating a pseudo-element and applying the gradient and animation to that instead of the main element. Here's an example:

In this example, we've created a pseudo-element ( :before ) and applied the gradient and animation to that instead of the main element. This works around the bug in Safari and allows the animation to work correctly.

Gradient animations are a great way to add visual interest to your website, but they can be tricky to get working correctly in all browsers. If you're having trouble with gradient animations in Safari, try using the workaround we've provided in this article. With a little bit of extra code, you can ensure that your animations work correctly in all browsers.

  • CSS Gradient Animations Not Working in Safari ( del1t.me )
  • CSS Gradient Animation Not Working in Safari ( stackoverflow.com )

Discover how to fix gradient animation not working in Safari and enhance your web development skills.

Binding live chart static data in wpf: import csv file and display values in cartesianchart.

In this article, we'll explore how to import CSV data and display it as live chart values in a WPF application using the LiveChart library.

Reading NetCDF Files in C#.Net: A Beginner's Guide for Windows Applications

Learn how to read NetCDF files in C#.Net for Windows Applications using appropriate libraries. This beginner's guide will walk you through the steps to develop a NetCDF reader in C#.Net.

Tags: :  GradientAnimation Safari WebDevelopment

Latest news

  • FullCalendar 'Today' Button Not Working in Inspect Mode
  • Receiving Continuous JSON Message Data Through C# UDP Listener in a Locationing System
  • Cancel Export using azcli instead of clicking Azure
  • Impala to Hive: Converting a Select Query with Load Date
  • Dynamically Creating Task Dependencies in Airflow
  • NGINX, Angular, and SSR: Route Changes Not Working
  • Counting the Number of Courses Registered by Student '이홍근' in MySQL
  • Binding OpenVPN Interfaces: Python Unable to Connect, but curl Commands Work Selectively
  • Android Jetpack Compose: Implementing Real-time Task List Updates
  • Custom Attribute Validators Won't Run in Abstract Class Derived
  • Generating Good Questions from Answer: Training a Model with USAFT Orders
  • Adding General Progress Bar During File Copying Process (Leaving Progress Bar Files Untouched)
  • Microservices with Function App APIM: OAuth2.0 Azure AD Authentication and Token Propagation
  • MethodsFromSql: Interpolated Queries in Entity Framework Core not Working as Expected
  • Preserving Output Filename Case with R's writeStatTransfer Function
  • Integrating AWS API Gateway with ECS Fargate Health Endpoint using OpenAPI 3.0
  • Maven Dependency Error: Unable to resolve Kotlin project with 'com.github.PhilJay:MPAndroidChart'
  • Resolving TypeError: Uncaught TypeError: Cannot read property 'getElementById' of null in Software Development
  • Python Code: Getting Data from QuestDB and Inserting into a Table
  • Supply Chain Optimization Modeling in Python using HiGHS
  • Managing Wishlist Items in a Software Development Application
  • Importing 3D (Animated) Models into Java: A Newcomer's Guide
  • Resolving CORS Issue with POST Requests in Spring Security for Authentication and Registration
  • SSIS Package in Visual Studio 2022 Triggering Wrong Script Component PostExecute Method on SQL Server 2019
  • Changing the OK mark in Bootstrap Select
  • Text Getting Cut: A Common Email Issue and Its Solutions
  • Getting Started with React Tailwind and Chakra-UI
  • Replacing Deprecated Microsoft.AspNetCore.Identity Package in Blazor Server App
  • Troubleshooting Segmentation Fault Errors in Software Development
  • Adding Clickable Buttons to GitHub: Implementing Workflows
  • Modifying Multiple Values in XML Files with XMLStarlet: One-Line Solutions
  • Accessing Specific Fields in POSTMAN Response from a Third-party API
  • Slow GET Requests for Tiny JS Assets from S3 (West Coast vs East Coast)
  • Debugging Terminal Process Exit Code -65536 in Visual Studio Code
  • Handling Duplicate Values in Data: The Case of 'ChangeValues' in R

Safari CSS Reference

  • Table of Contents
  • Jump To…
  • Download Sample Code

CSS Property Functions

This chapter describes the functions you can use with supported CSS properties.

Gradient Functions

Gradient functions can be passed to the background and background-image properties.

Specifies an intermediary color value for a gradient.

The point in the gradient that should have the specified color value. Represented as a percentage or a decimal value between 0 and 1 .

The color of the gradient at the stop.

For more information, see -webkit-gradient .

Available in Safari 4.0 and later.

A convenience function for the color-stop function that specifies the first color stop in a gradient.

Equivalent to calling color-stop() with a stop value of 0% .

A convenience function for the color-stop function that specifies the last color stop in a gradient.

Equivalent to calling color-stop() with a stop value of 100% .

-webkit-gradient

Generates a gradient image.

The type of gradient. Can be linear or radial .

The point in the image at which the linear gradient begins.

The point in the image at which the linear gradient ends.

A color-stop() function indicating the desired color for the gradient at a particular point in its progression.

The center point of the inner, starting circle in a radial gradient.

The radius of the inner, starting circle in a radial gradient.

The center point of the outer, ending circle in a radial gradient.

The radius of the outer, ending circle in a radial gradient.

The point corresponding to the top left corner of the image.

The point corresponding to the bottom left corner of the image.

The point corresponding to the top right corner of the image.

The point corresponding to the bottom right corner of the image.

-webkit-gradient() can be used in any place an image URL is used.

A linear gradient determines its color by interpolating between values specified by the color-stop() functions provided. Each color-stop() function specifies a percentage or a decimal between 0 and 1 and a color, indicating that the gradient should have the specified color value at the specified fraction of the gradient’s length. The shorthand functions from() and to() are supported as special-case color-stop() functions. The following example creates a linear gradient that shifts from yellow to orange in its first half and from orange to red in its second half, moving from the top left of the image to the bottom right of the image:

A radial gradient specifies its start and end with two (typically concentric) circles, each identified by a center point and radius. The color value at a point between the circumference of the inner circle and the circumference of the outer circle is determined by interpolating between color-stop() functions. The color value inside the inner circle is the color value of the first color-stop() function.

-webkit-linear-gradient

Generates a linear gradient image.

Specifies the gradient line which gives the gradient a direction and determines how color stops are positioned. Possible values are described in “Constants.” The default value is top .

Optionally, specifies the gradient line as an angle value where 0 degrees is east, 90 degrees is north, and positive angles are counter-clockwise.

A color for the gradient at a particular point in its progression. You can specify multiple color stops including a start and end color.

Color stops are expressed as two values with the following syntax: color | stop .

The color of the gradient at the stop. This parameter is mandatory.

The point in the gradient that should have the specified color value. The position can be specified in pixels or as a percentage of the gradient line. When a position is not specified, the browser distributes the color stop evenly between the adjacent color stops. Color stops at the same position result in sharp color changes.

The bottom side of the image.

The bottom left corner of the image.

The bottom right corner of the image.

The left side of the image.

The top side of the image.

The top left corner of the image.

The top right corner of the image.

The right side of the image.

Parameters that have default values are optional. However, two or more color stops are required to render a gradient.

For example, you can create a paper roll effect on one side:

This can be combined with another gradient to create a ribbon with a diagonal edge:

Available in Safari 5.1 and later.

Available in iOS 5.0 and later.

-webkit-radial-gradient

Generates a radial gradient image.

The center point of the cirlce or ellipse. This parameter allows you to move the origin of the shape. The position can be specified in terms of pixels or percentages of the image or using the keywords top , left , center , right , or bottom . The default is center .

The shape of the radient. Possible values are circle and ellipse . The default is ellipse .

The size of the radient. Possible values are closest-side , closest-corner , farthest-side , farthest-corner , contain , and cover . The default is cover .

Optionally, specifies the shape of an eclipse by providing two lengths: the length of the horizontal and vertical axes of the ellipse. The axis length is the length from the center of the ellipse to the edge, not the diameter. The lengths must be non-negative.

Optionally, specifies the shape of an eclipse by providing two percentage values: the percentage of the horizontal and vertical axes of the eclipse relative to the width and height of the box. The percentages must be non-negative.

For example, specify a gradient that progresses equally from red to green and then green to blue as follows:

Specify a gradient where red starts at 20px and blue starts at 90% with other colors distributed between as follows:

Create a sharp color change between green and purple as follows:

Parameters that have default values are optional. However, one or more color stops are required to render a gradient. If only one parameter is provided before the color stops and it could be interpreted as either a position or an explicit size, it is assumed to be a position.

For example, the following gradient is centered in the box and is large enough to fill it to the corners:

This is equivalent to:

You can also specify an alternate origin than center as follows:

Examples of specifying the shape and size of the gradient are:

where circle specifies the shape and closest-corner specifies the size.

You can also specify the ending radius of the gradient explicitly and separately for the horizontal and vertical axes:

where 5em is the x-value and 40px is the y-value.

If only percentages appear before color stops, the parameters are interpreted as a starting point, not the size of the ellipse:

-webkit-repeating-linear-gradient

Generates a linear gradient where the specified color stops repeat in both directions to fill the image.

Specifies the gradient line as an angle value where 0 degrees is east, 90 degrees is north, and positive angles are counter-clockwise.

The parameters are the same as -webkit-linear-gradient except the color stops are repeated. If a parameter is omitted, the default value is used.

The specified color stops are repeated infinitely in both directions by aligning them end-to-end. For example, this gradient:

is interpreted as:

Note that the boundary between the last color stop and the first color stop may result in a sharp color change. To avoid this, use the same color in the first and last color stop as in:

-webkit-repeating-radial-gradient

Generates a radial gradient where the specified color stops repeat in both directions to fill the image.

The starting point of the radial gradient. This parameter allows you to move the origin of the shape. The position can be specified in terms of pixels or percentages of the image or using the keywords top , left , center , right , or bottom . The default is center .

Specifies the shape of an eclipse by providing two lengths: the length of the horizontal and vertical axes of the ellipse. The axis length is the length from the center of the ellipse to the edge, not the diameter. The lengths must be non-negative.

Specifies the shape of an eclipse by providing two percentage values: the percentage of the horizontal and vertical axes of the eclipse relative to the width and height of the box. The percentages must be non-negative.

The parameters are the same as -webkit-radial-gradient except the color stops are repeated. If a parameter is omitted, the default value is used.

For example, you can create a bulls-eye effect as follows:

Timing Functions

Timing functions specify the easing technique for animations.

cubic-bezier

Specifies a cubic Bézier curve.

cubic-bezier(P1x,P1y,P2x,P2y)

First point in the Bézier curve.

Second point in the Bézier curve.

A cubic Bézier curve is defined by four control points, P0 through P3 . P0 and P3 are always set to (0,0) and (1,1) . This function is used to set the values for the points in between, points P1 and P2 . Each point is specified by both an x and y value.

Available in Safari 3.1 and later.

Available in iOS 2.0 and later.

Defines steps from one frame to another, not a smooth transition.

steps(number, point)

The number of intervals in the function. Must be greater than 0 .

The point at which the change of values occur within the interval. Possible values are start or end . The default value is end .

Stepping functions are appropriate for progress indicators. A stepping function is defined by a number of equal duration intervals and whether the change in output percentage happens at the start or end of the interval.

Transform Functions

Transform functions can be passed to the -webkit-transform property.

Specifies a 2D transformation in the form of a transformation matrix of six values.

matrix(m11, m12, m21, m22, tX, tY)

Elements of a 2 x 2 matrix in column-major order.

The x and y translation elements.

Passing matrix(a,b,c,d,e,f) is equivalent to applying the transformation matrix [a b c d e f] .

Specifies a 3D transformation as a 4 x 4 matrix.

matrix3d(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m31, m33)

Defines a 4 x 4 homogeneous matrix of 16 values in column-major order ( 0,0 ; 0,1 ; 0,2 ; ...).

Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later.

perspective

Specifies a perspective projection matrix.

perspective(depth)

The distance, in pixels, of the z=0 plane from the viewer.

This matrix maps a viewing cube onto a pyramid whose base is infinitely far away from the viewer and whose peak represents the viewer's position.

The viewable area is the region bounded by the four edges of the viewport (the portion of the browser window used for rendering the webpage between the viewer’s position and a point at a distance of infinity from the viewer).

Lower values for this property give a more flattened pyramid and therefore a more pronounced perspective effect. A value of 1000 pixels gives a moderate amount of foreshortening, and a value of 200 pixels gives an extreme amount.

Specifies a 2D rotation around the origin of the element.

rotate(angle)

The rotation angle. The angle may be specified using deg , rad or grad units.

The rotation operation corresponds to the matrix [cos(angle) sin(angle) -sin(angle) cos(angle) 0 0] . The origin of the element is specified using the -webkit-transform-origin property.

Specifies a clockwise 3D rotation.

rotate3d(x, y, z, angle)

The [x,y,z] direction vector for the rotation.

If the direction vector is not of unit length, it will be normalized. If the direction vector cannot be normalized, such as [0, 0, 0] , the rotation will not be applied.

Specifies a clockwise rotation by the given angle about the x-axis.

rotateX(angle)

Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later. Available in iOS 2.0 and later.

Specifies a clockwise rotation by the given angle about the y-axis.

rotateY(angle)

Specifies a clockwise rotation by the given angle about the z-axis.

rotateZ(angle)

The angle of the rotation. The angle may be specified using deg , rad or grad units.

Specifies a 2D scale operation.

scale(scaleX [, scaleY])

The scaling factor to apply in the x direction.

The scaling factor to apply in the y direction. If not specified, defaults to scaleX .

Specifies a 3D scale operation.

scale3d(scaleX, scaleY, scaleZ)

The scaling factor to apply in the y direction.

The scaling factor to apply in the z direction.

Scales in the x direction.

The scaling factor to apply to the x direction.

This function specifies a scale operation using the [sx, 1, 1] scaling vector.

Scales in the y direction.

The scaling factor to apply to the y direction.

This function specifies a scale operation using the [1,sy,1] scaling vector.

Scales in the z direction.

The scaling factor to apply to the z direction.

This function specifies a scale operation using the [1,1,sz] scaling vector.

Specifies a skew transformation along the x and y axes by given angles.

skew(angleX [, angleY])

The angle of the skew along the x-axis. The angle may be specified using deg , rad or grad units.

The angle of the skew along the y-axis. The angle may be specified using deg , rad or grad units. If not specified, defaults to 0 .

Specifies a skew transformation along the x-axis by the given angle.

skewX(angle)

The angle of the skew. The angle may be specified using deg , rad or grad units.

Available in Safari 3.1 and later. Available in iOS 2.0 and later.

skewY(angle)

Specifies a 2D translation vector.

translate(deltaX [, deltaY])

The number of units to translate along the x-axis. This value may be a percentage or a length.

The number of units to translate along the y-axis. If not specified, the y translation defaults to 0 . This value may be a percentage or a length.

translate3d

Specifies a 3D translation vector.

translate3d(deltaX, deltaY, deltaZ)

The number of units to translate along the y-axis. This value may be a percentage or a length.

The number of units to translate along the z-axis. This value may be a percentage or a length.

Specifies a translation in the x direction.

translateX(deltaX)

Specifies a translation in the y direction.

translateY(deltaY)

Specifies a translation in the z direction.

translateZ(deltaZ)

Filter Functions

Filters are visual effects that can be applied to images and other HTML elements. These functions can be concatenated in any order as parameters to the -webkit-filter property. These functions can be animated over time with the -webkit-animation property.

Applies a Gaussian blur to the element.

The blur radius, in pixels.

The radius is a specific CSS length and does not accept percentage values.

Available in Safari 6.0 and later.

Applies a linear multiplier to the image, making it brighter or darker.

The amount of brightness, as a percentage.

An amount of -100% will create an image that is completely black. An amount of 100% will create an image that is completely white. An amount of 0% leaves the input unchanged.

Adjusts the contrast of the element.

The amount of contrast, as a percentage.

An amount of 0% will create an image that is completely gray. An amount of 100% leaves the image unchanged. Amounts in between linearly affect the contrast.

drop-shadow

Applies a drop shadow effect to the image.

The horizontal offset of the shadow, in pixels.

The vertical offset of the shadow, in pixels.

The blur radius of the shadow, in pixels.

The color of the shadow.

The function accepts the same parameters as the -webkit-box-shadow property, with the exception that the inset keyword is not allowed.

Desaturates the image.

The percentage of desaturation.

An amount of 100% is completely grayscale. An amount of 0% leaves the image unchanged.

The number of degrees around the color circle the image’s color samples will be adjusted.

An angle of 0deg leaves the image unchanged.

Inverts the colors of the image.

The percentage of inversion.

An amount of 100% is completely inverted. An amount of 0% leaves the image unchanged. Amounts in between are linear multipliers on the effect.

Applies transparency to the image.

The percentage of opacity.

An amount of 0% is completely transparent. An amount of 100% leaves the image unchanged.

Saturates the image.

The percentage of saturation.

An amount of 0% is completely unsaturated. An amount of 100% leaves the image unchanged. Amounts over 100% are allowed, providing super-saturated results.

Applies a sepia effect to the image.

The percentage of sepia effect to apply.

An amount of 100% is completely sepia. An amount of 0% leaves the input unchanged. Amounts in between are linear multipliers on the effect.

JavaScript Helper Functions

-webkit-canvas.

Specifies a canvas for drawing programmatically with Javascript.

The name of the canvas.

The -webkit-canvas() function can be used in any place an image URL is used.

Canvases specified with the -webkit-canvas() function can be accessed in Javascript with the method getCSSCanvasContext() , which returns a CanvasRenderingContext object. The identifier passed to getCSSCanvasContext() should be the same as the value for canvas .

Specifying a new width or height for the canvas in subsequent calls to getCSSCanvasContext() clears the canvas buffer.

Copyright © 2016 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2016-10-27

Sending feedback…

We’re sorry, an error has occurred..

Please try submitting your feedback later.

Thank you for providing feedback!

Your input helps improve our developer documentation.

How helpful is this document?

How can we improve this document.

* Required information

To submit a product bug or enhancement request, please visit the Bug Reporter page.

Please read Apple's Unsolicited Idea Submission Policy before you send us your feedback.

CSS Individual Transform Properties in Safari Technology Preview

Avatar of Geoff Graham

The WebKit blog details how to use individual CSS Transform properties in the latest version of Safari Technology Preview. This brings the browser in line with the CSS Transforms Module Level 2 spec , which breaks out the translate() , rotate() and scale() functions from the transform property into their own individual properties: translate , scale , and rotate .

So, instead of chaining those three functions on the transform property:

…we can write those out individually as their own properties:

If you’re like me, your mind immediately jumps to “why the heck would we want to write MORE lines of code?” I mean, we’re used to seeing individual properties become sub-properties of a shorthand, not the other way around, like we’ve seen with background , border , font , margin , padding , place-items , and so on.

But the WebKit team outlines some solid reasons why we’d want to do this:

  • It’s simpler to write a single property when only one function is needed, like scale: 2; instead of transform: scale(2); .
  • There’s a lot less worry about accidentally overriding other transform properties when they’re chained together.
  • It’s a heckuva lot simpler to change a keyframe animation on an individual property rather than having to “pre-compute” and “recompute” intermediate values when chaining them with transform .
  • We get more refined control over the timing and keyframes of individual properties.

The post points out some helpful tips as well. Like, the new individual transform properties are applied first — translate , rotate , and scale , in that order — before the functions in the transform property.

Oh, and we can’t overlook browser support! It’s extremely limited at the time of writing… basically to just Safari Technology Preview 117 and Firefox 72 and above for a whopping 3.9% global support:

The post suggests using @supports if you want to start using the properties:

That’s the code example pulled straight from the post. Modifying this can help us avoid using the not operator. I’m not sure that’s an improvement to the code or not, but it feels more like progressive enhancement to do something like this:

That way, we clear the shorthand functions and make way for the individual properties, but only if they’re supported.

Individual CSS Transform Functions

' src=

Get Value of CSS Rotation through JavaScript

Now that css custom properties are a thing, all value parts can be changed individually.

Having the separate properties is great, it probably will produce less code not more (think overrides that used to reproduce everything they don’t override) and help make code more modular. Why they needed yet another syntax is beyond me. What we gain without colons we lose in cognitive overhead.

My kingdom for a CSS syntax unification. Lists should be either comma separated or not. Slashes are not a list item delimiter. Properties start with a name, are defined with the value after a colon. Functions are functions and have a name and accept a (rule-following delimited) list of parameters. Nested structures have braces. Once all that exists, shorthand/longhand follows a simple rule: shorthand is sugar for longhand.

Chrome also supports individual transform properties behind the Experimental Web Platform features flag, which can be enabled from chrome://flags :

enabling the flag in Chrome

I’m personally a bit mixed about their utility. I’d go for “really useful in some cases, but most of the times not an option”.

My biggest problem is they can only get applied in a certain order (and, save for some exceptions, transform order matters). Which is not the order I most often apply transform functions in. I normally use transforms to distribute elements in a logical pattern in 2D or 3D. This means starting with one or more rotations and only then applying a translation. And here we also have the issue that, when I distribute items in 3D, I normally first have a rotatey() , then a rotatex() and this only allows for a single rotation. And of course there’s the possibility of filling out the matrices, multiplying them, getting the trace and computing everything else that’s needed to combine them into a single rotate3d() . But that’s a pain.

However, one case where I find them useful is where I only have a single rotation and a uniform scale that I want to animate and I need different timing functions for the two. Like in the case of this cube animation or for these triangular openings .

safari css gradient problem

safari css gradient problem

What You Need to Know about Modern CSS (Spring 2024 Edition)

My goal with this bookmarkable guide is to provide a list of (frankly: incredible) new additions to CSS lately. There is no hardline criteria for this list other than that these things are all fairly new and my sense is that many people aren’t aware of these things. Or even if they are, they don’t have a great understanding of them and could use a plain language explanation of what it is, why they should care , and a bit of reference code. Maybe that’s you.

I’d like to work on our collective muscle memory on these features. Like I said , “even if you know about this stuff, it takes time to build the muscle memory around it.”

There is quite a bit more syntax, detail, and nuance to these things than I am presenting here. I want you to know what’s possible, reference the most basic usage and syntax, then dig deeper when you need to.

Container Queries (Size)

What are size container queries.

Container Queries allow you to write styles that apply to the children of a container element when that container matches certain media conditions, typically a width measurement.

When should you care?

If you’ve ever thought: I wish I could make styling decisions based on the size of this element, not the entire page like @media queries force me to do. Then using @container queries are for you! People who work on design systems or heavily component-based websites will probably mostly use Container Queries to style things based on size, because the size of the entire page is a poor proxy for the size of a component.

Basic Demo of Usage

Use the resizer in the middle to see the calendar change layout depending on how much space it has. It has three breakpoints of its own.

Container Queries (Style)

What are style container queries.

Container Style Queries allow you to apply styles when a given Custom Property has a given value.

Have you ever wanted a mixin in CSS? As in, you set one property but get multiple properties. Sass made mixins fairly popular. You can do that with a Style Container Query. But just like how Sass had variables then CSS variables turned out to be more powerful and useful, Style Container Queries are likely to be more powerful and useful, because they respect the cascade and can be calculated and such.

Container Units

What are container units.

Container Units (literally units, like px , rem , or vw ) allow you to set the size of things based on the current size of a container element. Similar to how with viewport units 1vw is 1% of the browser window width, 1cqw is 1% of the width of the container (although I’d recommend you use cqi instead, the “logical equivalent”, meaning the “inline direction”).

The units are cqw (“container query width”), cqh (“container query height”), cqi (“container query inline”), cqb (“container query block”), cqmin (smaller of cqi and cqb ), and cqmax (larger of cqi and cqb ).

If the sizing of anything in an element feels as if it should be based on the current size of the container, container units are essentially the only way. An example of this is typography. A typical Card element may deserve a larger header text when it happens to be rendered larger, without something like a class name needing to be added to control that. (I’m a fan of this demo .) Even a container query is clunky comparatively.

This element uses container query units for not only the font-size , but the padding , border , and margin as well.

The :has() Pseudo Selector

What is the :has() selector.

The :has() selector allows you to conditionally select an element when elements deeper in the DOM tree of the original element match the selector you put inside :has() .

If you’ve ever wanted a “parent” selector in CSS, :has() can do that, but it’s more powerful than that, as once you’ve selected the parent you want, you can again drill back down. Jhey Tompkins once called it a “family selector” which a nice way to think about it. You can also combine it with :not() to build a selector when an element doesn’t “have” a matching element inside.

View Transitions

What are view transitions.

There are two types of View Transitions:

  • Same-Page Transitions (Require JavaScript)
  • Multi-Page Transitions (CSS Only)

They are both useful. A same-page transition involves and animation when the DOM is changed without the page changing, like a list being sorted. A multi-page transition is for animating elements between page loads, like a video thumbnail transitioning into a video element. This is the basic syntax for a same-page transition:

For multi-page transitions: you need this meta tag:

Then any element you want to transition between pages you make sure has a totally unique view-transition-name applied in the styles, on both the outgoing page and incoming page.

Users can understand an interface better if an element moves to a new position rather than instantly being there. There is an animation concept called tweening where the animation is automatically created based on a starting and ending state. View Transitions are essentially tweening. You can control aspects of the animation, but for the most part the animation is automatically created based on the starting and ending state of the DOM, rather than you having to be really specific about the animation details.

This is an example of a same-page view transition:

What is nesting?

Nesting is a way of writing CSS that allow you to write additional selectors within an existing ruleset .

Nesting is mostly a CSS authoring convenience, but the fact that it can group related CSS nicely together and prevent you from having to repeat writing a selector can mean avoiding mistakes and making the CSS easier to read. Nested CSS can also be something of a footgun in that may encourage writing CSS that matches the nesting of HTML in an unnecessary way, increasing the specificity and decreasing the reusability of some CSS.

The only major difference from Sass-style nesting is that you can’t combine the & directly.

Scroll-Driven Animations

What are scroll-driven animations.

Any animation that is tied to the scrolling of an element (often the page itself) can now be done in CSS rather than needing to bind DOM scrolling events in JavaScript. They come in two varieties:

  • The scroll progress of the element. ( animation-timeline: scroll() )
  • An element’s current viewable position within the element. ( animation-timeline: view() )

Imagine a reading progress indicator bar that fills from 0% to 100% as the user scrolls down the page. That can be done with an animation moving the background-position of an element tried to the overall scroll position of the page. Doing this in CSS instead of JavaScript is good for performance .

The other major use case covered by scroll-driven animations is to run an animation as an element enters (or leaves!) the viewport. You have lots of control over the details, like when the animation starts and ends based on how visible the element is.

Basic Example of Usage

This is the demo from when we looked at image zooming and page scrolling .

Anchor Positioning

What is anchor positioning.

Anchor positioning allows you to place items relative to where another element is. Seems pretty obvious when put like that, but that’s what it is. You declare an element an anchor and give it a name, then can position elements to the top/right/bottom/left (or center, or the logical equivalents) of the anchor.

Once you can use this freely, you’ll have to care less about exact DOM positioning of elements (aside from accessibility concerns). The way it is now, the element you want to position relative to another has to be a child element and for there to be a positioning context to work within. This can dictate where elements go in the DOM, whether or not that makes sense.

The big use cases are going to be tooltips and custom context menus.

At the time I’m publishing this, this only works in Chrome Canary with the “Experimental Web Platform Features” flag enabled.

What is Scoped CSS?

Scoping in CSS is in the form of an @scope at-rule that declares a block of CSS to only apply to the given selector. And optionally, stop applying at another given selector.

You can also scope CSS by applying a class and nesting within that class. But @scope has a few tricks up it’s sleeve that can make it interesting. The “donut scope” option is a unique ability it has:

More logical proximity styling is another useful feature. This is a bit tricky to explain but once you see it you can’t unsee it. Consider theming. You have a .dark selector and a .light selector. If you only ever use one on the entire page, that’s fine, but if you end up nesting them at all, because they have the same specificity, whichever one you define later is technically a bit more powerful, and can win out even if it doesn’t make sense to. Minimal example:

You might think the paragraph element in there would have the color purple, but it will actually be red . That’s just awkward, but it can be fixed with @scope . When scoped selectors match, as Bramus says , “it weighs both selectors by proximity to their scoping root”, and since “light” is closer here, it would win.

My favorite though is the ability to drop in a <style> tag in the DOM and have it apply scoped styles only to that bit of the DOM, without having to name anything.

Cascade Layers

What are layers.

Cascade Layers in CSS are an extremely powerful syntax that affects the styling strength of a chunk of styles. You can optionally name and order layers (if you don’t explicitly order them, they order in source order). Styles in higher layers automatically beat styles in lower layers, regardless of selector strength. Styles not within layers are the most powerful.

We’re used to thinking that body#home is a much more powerful selector, thus the background will be #eee . But because there are unlayered styles here, that will win, making the background white .

You may have as many layers as you like and can order them upfront. I think layering is likely to become a best practice on new greenfield projects, and take shape something like:

One gotcha is that !important rules on lower layers are actually more powerful.

One clear way you get a lot of value out of CSS layers if you work on a project that uses a third-party styling library. You can put that library on a lower layer than the styles that your team writes, and you won’t have to worry about fighting the third-party library in terms of selector strength. Your styles on a higher layer will always win, which is likely to create cleaner and more maintainable CSS.

For example, put all of Bootstrap on a lower layer just using the layer keyword and then any styles you write after that will win, even if Bootstrap itself uses a higher power selector.

Logical Properties

What are logical properties.

Logical properties are alternatives to properties that specify a direction. For example, in a left-to-right language like English, the inline direction is horizontal and the block direction is vertical, so margin-right is equivalent to margin-inline-end and margin-top is equivelant to margin-block-start . In a right-to-left language like Arabic, margin-inline-end changes to the equivalent of margin-left , because that is the end side of the inline flow of elements. There are a lot of CSS properties and values that have a directional component like this (border, padding, offset, set), so the trick is understanding inline and block flow and using the correct start or end value.

Often when you are declaring directional information in CSS, what you mean is “in the inline direction of text”. That might sound strange, but imagine a button and the space between an icon and the text. If you apply margin-right to the icon to space it away from the text, but then the page is translated to a right-to-left language, that spacing is now on the wrong side of the icon. What you meant was margin-inline-end on the icon. If you code your side using logical properties in this way, it will automatically translate better without writing any additional conditional code.

What is the Display P3 Color Space?

We’re largely used to the sRGB color space on the web. That’s what hex colors use, and the rgb() , hsl() , and hsb() functions. Many displays these days are capable of display a much wider range of colors than sRGB is capable of describing, so being limited to that color space sucks. The Display P3 color space is about 50% wider than sRGB, expanding in the direction of more rich and vibrant colors. New CSS functions, which can even use different color models that have their own useful properties, allow us to declare colors in this space.

If you want to use colors that are quite vibrant, you’ll need to tap into colors in the P3 Color Space. Using newer color models (and functions) can do this, and are very useful for a variety of other things.

For example, the oklch() function (and thus OKLCH color model ) can display any color any other method can (plus P3), has a similar human readability in common with hsl() , and has “uniform perceived brightness”, so that the first number (lightness) behaves way more predictably than it does in hsl() . That’s awfully nice for color on the web. But it’s not the only new color model and function! I find the oklab color model generally best for gradients.

You can edit these <style> blocks because I made them display: block; and contenteditable :

Color Mixing

What is color-mix() .

The color-mix() function in CSS allows you to, wait for it , mix colors. This kind of thing has been baked into CSS processing tools for a long time, and as typical of CSS evolution, now that it’s in native CSS, it’s more thoughtful and powerful than it ever was in a processor.

When you should care?

Have you ever wanted to darken or lighten a color you already have on the fly? That’s one of the things color-mix() can do. Color mixing can happen in a specific color model which means you can take advantage of how that models works. For example, the perceptually uniform brightness of OKLCH makes it sensible to use for adjusting brightness. You can make whole color palettes using color-mix() .

Browser Support

Margin trim, what is margin-trim .

The margin-trim property removes any margin in the direction specified from the selected container at the end of that direction. Imagine you have five blocks in a row that all have right margin on them in a container. You might select the :last-child to remove the right margin. With margin-trim you can ensure that margin is removed from the parent element itself.

You know how the gap property of flexbox and grid is… awesome? It only puts spacing between elements. Well, if you need to apply spacing between elements but you’re in a position where you can’t use gap , margin-trim is awfully nice as it means you apply directional margin to all the children and not worry about an additional fancy selector to select the first or last one and remove that unneeded final margin. It might end up a best practice .

The last paragraph here is a notorious situation where the bottom margin on it creates more space at the bottom than any of the other edges. With margin-trim we can ensure it’s sliced off without having to select that last paragraph and manually remove it.

Text Wrapping

What is text-wrap .

The text-wrap property likely isn’t in your long term CSS memory. It’s capable of text-wrap: nowrap; , but we generally think of white-space: nowrap; for this. But now, text-wrap has two new tricks up it’s sleeve:

  • text-wrap: balance; — Attempt to make equal-width lines when text wraps.
  • text-wrap: pretty; — Avoid orphans.

A headline with one word orphaned onto the next line just looks really awkward and could be considered poor typography. There wasn’t a great way to solve this before, short of somewhat awkward tricks like inserting a &nbsp; instead of a normal space between the last two words. Balancing a headline prevents this, but goes further in making the multiple lines of text generally the same width. Using pretty is more focused just on orphan prevention alone, making it more appropriate for body text.

What is Subgrid?

Subgrid is an optional part of using CSS grid that is relevant when you are nesting gridded elements. By setting grid-template-columns: subgrid; or grid-template-rows: subgrid; on a grid-level element, you’re saying “inherit these columns or rows from my parent grid, where relevant”.

The point of using grids for layout is generally lining things up . Without subgrid , it means that child elements of a grid don’t have access to the grid lines of the parent grid, and thus lack the opportunity help line things up. Subgrid fills that gap. When DOM nesting is important for functionality or accessibility, like in a <form> , subgrid can help ensure things line up sensibly .

Things to keep an eye on…

The speed of CSS development doesn’t seem to have slowed down. There is plenty to continue to watch for and look forward to.

  • CSS Mixins & Functions — actual mixins and functions that take parameters
  • Relative Color Syntax — a way to manipulate the parts of colors in an intuitive and powerful way.
  • Interop 2024 — All the things that we can essentially bet on for being cross-browser compatible soon, including the relative color syntax above.
  • The CSS property field-sizing should help the long-standing difficult issue of auto-resizing form elements like textareas and input to the content they contain.
  • <selectmenu> in HTML is essentially a fully CSS styleable <select> , which is wild.

That’s just a few things to watch. You might as well subscribe to our feed as we’ll be doing the watching for you and then you’ll catch the next one.

Did I miss a relatively new favorite of yours? Let me know.

Wanna learn CSS from a course?

Frontend Masters logo

FYI, we have a full CSS learning path with multiple courses depending on how you want to approach it.

6 responses to “What You Need to Know about Modern CSS (Spring 2024 Edition)”

Avatar

Very helpful summary!

Avatar

Awesome post by one the most CSS saavy devs in CSS. Very helpful and thankful to FEM to post this contents free.

Avatar

Very helpful article, thank you very much!

However, please note that in “Scoping”, the example given with the three embedded divs and light/dark classes does not work. Contrary to what the article says, “some text” will use the “light” style. I am guessing this is an overly simplified version of the example given on the MDN page for @scope, which is slightly more convoluted: https://developer.mozilla.org/en-US/docs/Web/CSS/@scope#how_scope_conflicts_are_resolved

Avatar

You’re correct! Thank you. Selecting within the class exhibits the issue more clearly: https://codepen.io/chriscoyier/pen/oNOpqJK

Avatar

This is very useful article. However, I have a big problem with container queries, at least as you have described them. Problem 1: You are writing if/then code in CSS: that should be in JavaScript. Problem 2: The bigger issue: you are writing more code then you need to. In the example you used, you could have been handled the situation much easier, and with less code, with a class. style=”–variant: 1;” is class1 and style=”–variant: 2;” is class2. Your code would be simpler and easier to read in HTML, CSS and JS.

You are writing if/then code in CSS: that should be in JavaScript.

Do you feel that way about media queries? Hover states? Focus styles? Disabled styles? Validity checks? Heck, every selector is an if/then statement. If the selector matches, do the styles.

you could have been handled the situation much easier, and with less code, with a class. style=”–variant: 1;” is class1 and style=”–variant: 2;” is class2. Your code would be simpler and easier to read

I agree class changes are a very clear way to change the state of something. But changing the value of a custom property in CSS is a different beast entirely. You could change a custom property because of a :has() selector, or a media query, or a state change, or a million other things. In those cases, you don’t have the ability to change a class in the HTML. But with a style query, you can still change a whole chunk of styles when the custom property changes.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • CSS Formatter
  • How to use Google Fonts in CSS ?
  • How to use a "not equal" CSS attribute selector ?
  • How to Create a Responsive CSS Grid Layout ?
  • How to Apply an Ellipsis to Multiline Text in CSS ?
  • How to use Relative URL in CSS file and What Location is it Relative to ?
  • How to Make a Tooltip With a Bottom Arrow ?
  • How to add some non-standard font to a website in CSS ?
  • Which property is used to set the text direction ?
  • How to make an empty div take space ?
  • How to Display Element on Hover using CSS ?
  • How to prevent long words from breaking my div ?
  • How do min-content and max-content work ?
  • Is it Possible to Set Equivalent of a src Attribute of an img tag in CSS ?
  • Why Does z-index Not Work with Fixed Positioning in CSS ?
  • How to use drop-shadow on SVG element using CSS3 ?
  • What is the Outline effect to text ?
  • How to declare a partial border to a box ?
  • How to use text-overflow in a table cell ?
  • Is background-color:none valid CSS ?

How to Set Transparency with Linear Gradient in CSS ?

In web design, colors, and gradients play a vital role in crafting visually appealing websites. Incorporating transparency into specific elements can further enhance their visual impact. We’ll explore three methods for achieving transparency with linear gradients in CSS including, background image, linear gradients with RGBA colors , and HSLA colors .

These are the following approaches to set Transparency with Linear Gradient in CSS:

Table of Content

  • Background-image
  • Linear Gradient with RGBA Colors
  • HSLA Colors

Using background-image

In this approach, by adjusting gradient colors using the background-image property , we can determine how clear or opaque the image appears. This method adds attractiveness to our web designs. With the help of this method, we can set transparency to the images.

Example: Illustration of transparency Using background image property in CSS.

Using RGBA Colors

In this approach, we will use the rgba() function , this function lets us define colors using the red, green, and blue (RGB) color model, along with an alpha channel to control transparency. The alpha value, ranging from 0 (fully transparent) to 1 (fully opaque), determines how transparent each color stop is along the gradient.

Example: Illustration of transparency Using linear gradient with RGBA colors in CSS.

move2p1

Using HSLA Colors

In this approach, first create a centered box with a linear gradient background using HSLA colors , which allows for transparency. The gradient transitions from red (hue 0) to blue (hue 240) with 50% saturation and lightness, while the alpha value (0.5) controls the transparency level.

Example : Illustration of transparency with Linear Gradient in CSS Using HSLA Colors in CSS.

move2p2

Please Login to comment...

Similar reads.

  • CSS-Questions
  • Web Technologies
  • How to Use ChatGPT with Bing for Free?
  • 7 Best Movavi Video Editor Alternatives in 2024
  • How to Edit Comment on Instagram
  • 10 Best AI Grammar Checkers and Rewording Tools
  • 30 OOPs Interview Questions and Answers (2024)

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

IMAGES

  1. How to Remove Gradient on Dropdown Menus in Safari

    safari css gradient problem

  2. Css

    safari css gradient problem

  3. Create Beautiful CSS Gradients In Seconds with CSSGradient.io

    safari css gradient problem

  4. CSS repeating-linear-gradient broken at Safari 11?

    safari css gradient problem

  5. css

    safari css gradient problem

  6. Css

    safari css gradient problem

VIDEO

  1. Free fire# video Diamond 1 R#Shots noob to pro 💯🔥#shots 💯🔥VS😈😲

  2. CSS can't animate gradients, but SVG can

  3. Gradient

  4. Visualize Attention with LSTM

  5. How to allow specific website to open on your safari on iPhone

  6. Convolutional Neural Network (CNN) Part 1

COMMENTS

  1. css

    I am having trouble showing a linear gradient in Safari and Chrome. In Firefox it shows up fine. I am trying: background: -webkit-linear-gradient(center top , #9E9E9E, #454545) repeat scroll 0 0 transparent; background: -moz-linear-gradient(center top , #9E9E9E, #454545) repeat scroll 0 0 transparent; background: -ms-linear-gradient(center top , #9E9E9E, #454545) repeat scroll 0 0 transparent ...

  2. css

    tested your updated styles in el capita/safari 9.1 and yosemite/safari 8 and works in all cases. must be something else. we cannot step forward unless you share your full codes - Simon Kraus Jul 20, 2016 at 20:59

  3. Problem with Linear Gradient in Safari

    Hey guys, i'm having problems with a linear gradient not showing up on safari (desktop). it's showing fine on chrome though: you can see it at climate-tech dot net the CSS i'm using is: #rt ...

  4. Using Gradients

    Use a CSS gradient anywhere that you can use an image, such as for the background of an element, an element border, or a mask. ... Safari supports two types of CSS gradients: linear and radial. This chapter describes both types of gradients. Safari 5.1 on the desktop and Safari on iOS 5.0 use the -webkit-prefix for specifying gradients, ...

  5. linear gradient no longer working in safari 11 (high sierra)

    The code can be more sturdy if you use the newer syntax for linear-gradients and if you define that gradient as a background-image ISO a value for the content property on the pseudo element. So ISO this:

  6. Safari bug with gradients that fade to "transparent"

    CSS. .element { background: linear-gradient ( to bottom, red, transparent ); } There is a pretty big gotcha here, though. In Chrome (also Android), Firefox, and Edge, you'd be all good. But in Safari (also iOS), you'd not be good. The element on the left in each browser demonstrates the problem.

  7. Fixing Gradient Banding in Software Development: A Guide for Chrome and

    This article provides a solution for gradient banding issues that occur in Chrome and Safari when coding linear radial gradients. Learn how to fix this problem and improve your web development skills. ... A Guide for Chrome and Safari. Gradients are a common feature in web development, and they can be used to add visual interest and depth to a ...

  8. Gradient Support in Safari

    background: linear-gradient (to right, rgb (245, 245, 245, 0.8), #f5f5f5 65%); Still, it was not working on safari as expected maybe you have figured out the issue, but it took me more than 40 min ...

  9. How to Fix CSS Issues on Safari

    Displaying properties in Safari. There is a CSS appearance property used to display an element using a platform-native styling based on the users' operating system's theme. To make it work on Safari, we must set the appearance property to its "none" value. Also, use -WebKit-and -Moz-vendor prefixes.. Let's see an example, where we use this trick to make the border-radius property work on ...

  10. Multi-line Gradient Text Safari / iOS Fix (i.e., prevent ...

    Three weeks ago, Webflow added the CSS background-clip feature live to all users.. On Safari / iOS, multi-line gradient texts and backgrounds in parent divs do not work well with position: inline.This bug has been documented, but seemingly only in the annals of CSS Quirks Volume 54.. I've lost some sleep this past week in finding a fix.

  11. Fixing CSS Errors in Safari Desktop

    Common CSS Errors in Safari Desktop. Here are some of the most common CSS errors that can occur in Safari: Box model inconsistencies. Float and clear issues. Positioning and z-index problems. Gradient and opacity rendering differences. Flexbox and grid inconsistencies. 3. Box Model Inconsistencies.

  12. A Complete Guide to CSS Gradients

    A Complete Guide to CSS Gradients. Like how you can use the background-color property in CSS to declare a solid color background, you can use the background-image property not only to declare image files as backgrounds but gradients as well. Using CSS gradients is better for control and performance than using an actual image (of a gradient) file.

  13. Gradient Animation Not Working in Safari: A Solution

    Understanding the Problem. The issue with gradient animations in Safari is related to the way that the browser handles the animation and transform properties. Specifically, Safari has a bug that causes these properties to not work correctly with linear gradients that have an angle value specified. ... CSS Gradient Animation Not Working in ...

  14. CSS Property Functions

    A radial gradient specifies its start and end with two (typically concentric) circles, each identified by a center point and radius. The color value at a point between the circumference of the inner circle and the circumference of the outer circle is determined by interpolating between color-stop() functions. The color value inside the inner circle is the color value of the first color-stop ...

  15. linear gradient in Safari : r/css

    About the black in between - Safari takes the colors literally. So, if you change your gradient to background-image: linear-gradient(30deg, rgba(255, 204, 0, 0.7), rgba(255, 204, 0, 0.001) 50%); (applying the start color to the end as well), it should probably look better.

  16. Gradient Text with Safari Fix

    You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself. ... /* Below styles for setting a backround on text */ /* IMPORTANT: This does not work on buttons in safari */ background: linear-gradient(79deg, blue 0%, purple 121%); color ...

  17. CSS Individual Transform Properties in Safari Technology Preview

    The WebKit blog details how to use individual CSS Transform properties in the latest version of Safari Technology Preview. This brings the browser in line with the CSS Transforms Module Level 2 spec, which breaks out the translate(), rotate() and scale() functions from the transform property into their own individual properties: translate, scale, and rotate.

  18. css

    I noticed that they used -90deg to 90deg, so I rewrote my -webkit-gradient- prefixed gradients in that range and now it works. And since Chrome uses linear-gradient, it uses the 180deg to 360deg gradients and it works. I left the problematic prefixed gradient commented out, to see the problem, uncomment it.

  19. What You Need to Know about Modern CSS (Spring 2024 Edition)

    Container Units What are Container Units? Container Units (literally units, like px, rem, or vw) allow you to set the size of things based on the current size of a container element.Similar to how with viewport units 1vw is 1% of the browser window width, 1cqw is 1% of the width of the container (although I'd recommend you use cqi instead, the "logical equivalent", meaning the "inline ...

  20. css

    I have a web site that uses CSS linear-gradient with color-mix for a background of a division. It shows up just fine in Safari on iOS and iPadOS 17.4.1. When do a screenshot, and select "Full Page", the background-image becomes all black and the text in the division is unreadable. This is what I am doing.

  21. How to Set Transparency with Linear Gradient in CSS

    Output: Using RGBA Colors. In this approach, we will use the rgba() function, this function lets us define colors using the red, green, and blue (RGB) color model, along with an alpha channel to control transparency.The alpha value, ranging from 0 (fully transparent) to 1 (fully opaque), determines how transparent each color stop is along the gradient.

  22. css

    That's why I made the gradient to have a size of 200% 200% and the I simply adjust the background position to have the same visual. Here is the final background: .box{. background: radial-gradient( farthest-side, rgba(218, 218, 216, 0.5) , transparent) top right/200% 200%,