Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3870936
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:46:32+00:00 2026-05-19T21:46:32+00:00

When an SVG is directly included in a document using the <svg> tag, you

  • 0

When an SVG is directly included in a document using the <svg> tag, you can apply CSS styles to the SVG via the document’s stylesheet. However, I am trying to apply a style to an SVG which is embedded (using the <object> tag).

Is it possible to use anything such as the following code?

object svg { 
    fill: #fff; 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T21:46:33+00:00Added an answer on May 19, 2026 at 9:46 pm

    Short answer: no, since styles don’t apply across document boundaries.

    However, since you have an <object> tag you can insert the stylesheet into the svg document using script.

    Something like this, and note that this code assumes that the <object> has loaded fully:

    var svgDoc = yourObjectElement.contentDocument;
    var styleElement = svgDoc.createElementNS("http://www.w3.org/2000/svg", "style");
    styleElement.textContent = "svg { fill: #fff }"; // add whatever you need here
    svgDoc.getElementById("where-to-insert").appendChild(styleElement);
    

    It’s also possible to insert a <link> element to reference an external stylesheet:

    var svgDoc = yourObjectElement.contentDocument;
    var linkElm = svgDoc.createElementNS("http://www.w3.org/1999/xhtml", "link");
    linkElm.setAttribute("href", "my-style.css");
    linkElm.setAttribute("type", "text/css");
    linkElm.setAttribute("rel", "stylesheet");
    svgDoc.getElementById("where-to-insert").appendChild(linkElm);
    

    Yet another option is to use the first method, to insert a style element, and then add an @import rule, e.g styleElement.textContent = "@import url(my-style.css)".

    Of course you can directly link to the stylesheet from the svg file too, without doing any scripting. Either of the following should work:

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet href="my-style.css" type="text/css"?>
    <svg xmlns="http://www.w3.org/2000/svg">
      ... rest of document here ...
    </svg>
    

    or:

    <svg xmlns="http://www.w3.org/2000/svg">
      <defs>
        <link href="my-style.css" type="text/css" rel="stylesheet" 
              xmlns="http://www.w3.org/1999/xhtml"/>
      </defs>
      ... rest of document here ...
    </svg>
    

    Update 2015: you can use jquery-svg plugin for apply js scripts and css styles to an embedded SVG.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to generate the following diagram using Image_GraphViz for PEAR. However It only
There is a bug in Inkscape where JPEG images included in an SVG document
Using SVG path, we can draw 99.99% of a circle and it shows up,
Using SVG via Inkscape: I have several <use> -tags, which are reusing the same
HTML5 supports SVG via the svg element. Other languages can be embedded within SVG
Objective: Apply CSS Filters to video using html5 and JavaScript. Contraints: The solution must
This is the svg I try to embed: <script type=image/svg+xml> <svg width=200 height=200 style=background-color:
I have an inline SVG with in an HTML5 document, and would like to
I have a simplr svg-graph and I'm trying to create a simple tooltip-popup for
I have a JSF 2 application which creates some SVG content. How can i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.