Skip to content

Clarify that CSS width/height properties only apply to outer svg elements#1059

Open
goldenboy777 wants to merge 2 commits intow3c:mainfrom
goldenboy777:1057-should-width-and-height-apply-to-nested-svg-elements-as-css-properties
Open

Clarify that CSS width/height properties only apply to outer svg elements#1059
goldenboy777 wants to merge 2 commits intow3c:mainfrom
goldenboy777:1057-should-width-and-height-apply-to-nested-svg-elements-as-css-properties

Conversation

@goldenboy777
Copy link
Contributor

Per the SVG WG resolution from 2026-02-05:

The CSS width/height properties are honored as presentation attributes for rect, image, foreignObject and outer-SVG elements and ignored by all other elements with the width/height attributes.

This change updates Section 7.8 (Sizing properties) to:

  • Clarify that CSS width and height properties apply only to the outermost <svg> element, not nested ones
  • Add a note explicitly stating that nested <svg>, <use>, and <symbol> elements have width/height attributes but do not accept them as CSS properties—they must be specified as XML attributes

@goldenboy777
Copy link
Contributor Author

@dirkschulze @karlcow @nikolaszimmermann, I have raised this pull request as per the resolution on SVG WG resolution from 2026-02-05, let me know if it's okay to merge this PR

Copy link
Member

@karlcow karlcow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for editing. Just a nit comment about potential examples.

Comment on lines +386 to +392
<p class='note'>
Other SVG elements, such as nested <a>'svg'</a> elements, the <a>'use'</a> element, and
the <a>'symbol'</a> element, also have <span class='attr-name'>'width'</span> and
<span class='attr-name'>'height'</span> attributes, but do not accept them as CSS properties.
On these elements, the width and height must be specified as XML attributes; CSS properties
with the same names are ignored.
</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there should be markup examples of what is working and not working.
Also probably all of these requires WPT tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have few WPTs for nested/inner svg already, (which I need to update as per the resolution)
https://wpt.fyi/results/svg/styling?label=master&label=experimental&aligned&q=nested

But I can add some more for the all the elements we are targeting.

Comment on lines +380 to +381
<a>'rect'</a>, <a>'image'</a>, <a>'foreignObject'</a>, and
the outermost <a>'svg'</a> element. All of these elements have <span class='attr-name'>'width'</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

I was reviewing this part of the specification yesterday, and the prose hides a bit what is happening.

I can see two possibilities. An algorithmic description of what should be done or a summary table.
https://bugs.webkit.org/show_bug.cgi?id=307332
It could be done in an different issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karlcow Thanks for the suggestion, rather than a separate PR I think addressing these issues in this PR itself might be better.

I have added the table as suggested in https://bugs.webkit.org/show_bug.cgi?id=307332, it seems a pretty good addition.

A few things to note here:

  1. I have removed the below line, cause as per the new resolution this is no longer applicable.
<p>Content dependent units used in 'width' and 'height' for inner SVG elements resolve to SVG's definition of <a><span class='prop-value'>auto</span></a>. These content dependent units include 
<a href="https://drafts.csswg.org/css-sizing-3/#valdef-width-min-content">'min-content'</a>, <a href="https://drafts.csswg.org/css-sizing-3/#valdef-width-max-content">'max-content'</a>, 
<a href="https://drafts.csswg.org/css-sizing-3/#funcdef-width-fit-content">'fit-content()'</a> and <a href="https://drafts.csswg.org/css-sizing-3/#funcdef-width-calc-size">'calc-size()'</a>.</p>
  1. I have added the table only for the auto value for now, but let me know if we should extend it.

  2. I have still kept the resolution of this PR as separate "notes/paragraph" cause I couldnt think of a better way to include them in the above table without messing things up.

Let me know your thoughts on this and whether some additions are needed.

@goldenboy777 goldenboy777 force-pushed the 1057-should-width-and-height-apply-to-nested-svg-elements-as-css-properties branch from 6760495 to 7255113 Compare February 17, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments