Is there a way to hide style.css within a source code in website?

Hello,
As I have set a different location and file for style.css, how can I hide it inside a source code in site?
Here’s an example:

themes/mytheme/style.css" rel=“stylesheet”>`

There is still a codex inside WP to be kept, but it is hidden as it is a codex within WP that needs to be kept.

I don’t see how or why you would hide your CSS.
The client needs to download the CSS in order to see your site the way you want it to look, therefore it must be publicly accessible.

2 Likes

I want to hide CSS because i don’t want to show on my site.

The browser needs to be able to read the CSS in order to use it.
If the browser can read it, the user can read it.

Not sure why you would ever need to hide CSS.

You may have a line like this in the head of your page:-

<link rel="stylesheet" type="text/css" href="css/style.css">

or a section like this:-

<style>
   /* Some CSS here...
</style>

You will have to delete these to remove your CSS.

The poster does not wish to remove his css, I believe, but they want to hide the code. Probably the poster does not want visitors to see the code because they do not want it copied and used by others, he wants to protect his investment in developing it. I can understand that but the unfortunate fact is that the way browsers work the .css has to be accessible which also means readable and downloadable. So in short, I do understand, but - not possible.

I think that is as useful of an explanation as saying you want to hide the CSS because you want to hide it.

If you want to hide it because you do not want it to be used by others then say that. HTML and CSS were not designed to support that and therefore it is essentially impossible to do. You might be able to make it more difficult for beginners like you to see it. Anyone with experience is not likely care.

If you need to hide it for security purposes because there is sensitive data then you really need to say that in your question.

They should say that. I have seen discussions erupt into a long useless discussion when people speculate and opinionate without the person asking the question clarifying the question.

1 Like

It is not possible to completely hide the style.css file from the source code of a website. The style.css file is a critical component of a website’s design and layout, and it needs to be accessible to web browsers in order to properly display the site’s visual elements.

That being said, there are techniques that can be used to make it more difficult for someone to access or modify the style.css file. One common technique is to minify or obfuscate the CSS code, which can make it harder for someone to read or modify the code by hand. There are many tools and plugins available for this purpose, including online minifiers and WordPress plugins.

Another technique is to use server-side code to generate the CSS code dynamically, rather than serving it as a static file. This can make it harder for someone to access the CSS file directly, as it is not stored as a separate file on the server. However, this technique requires more advanced development skills and may not be feasible for all websites.

Overall, while it is not possible to completely hide the style.css file from the source code of a website, there are techniques that can make it more difficult for someone to access or modify the code. However, it’s important to keep in mind that any security measures can be bypassed with sufficient knowledge and effort, so it’s always a good idea to use other security measures as well, such as secure hosting, strong passwords, and regular backups.

And there are equally available tools to format CSS so it is easy to read. Replacing the names with something irrelevant to the purpose of something can help make CSS more difficult to understand.

The CSS would still be available using the browser’s development tools.

Since we have come to the inevitable conclusion that you can’t hide CSS while at the same time publishing it on the internet, I’m going to close this topic, before it goes over the same ground again and attracts anymore spam and worthless, wordy, drivel spun from ChatGPT.

1 Like