I’m wondering if there is a way to stop people from copying code from a website. I know this may be a bit of a basic question, but can you really stop people from viewing the source code of a website? I’m thinking of a really hacky way of inserting it through an iframe, but I guess this will still be accessible through the source.
Any suggestions on whether this is possible would be great.
What does that mean? Your title says HTML/CSS and if that is what you are asking about then no, it cannot be protected. If you are thinking of something else in your mind then note that you do not say it for us.
HTML and CSS is “client-side” code, that is code that is sent from the server to the client.
If it’s sent to the client, the client can see it, copy it, do as they please. The only way to prevent this is to not send any code to the client, in which case they may see a blank screen, or in other words, not having a public website.
I would recommend disabling the right click action. This disables the user to right click, therefore disabling them to access the inspect element. I would do a quick google search to see snippets of possible solutions. There is another solution, one I don’t have much knowledge of, but it basically hashes your code so it’s unreadable and renders useless if copied.
I have been programming for nearly half a century and the term source code has existed since before my time. HTML has existed for less than 30 years.
Source code can absolutely refer to server-side code such as PHP. It seems strange to me to refer to HTML and CSS as source code; source code has logic. HTML and CSS are basically UI things; they are more of a word-processing format.
It does not disable the developer tool. And even if you disable that, it is possible to use HTTP (such as what CURL does) to get the HTML file and the others. So you might be able to make it difficult for the non-technical people from accessing the code but those of us that are more technically inclined can get around anything that someone thinks would work.
You will impress us if you can find that but you cannot.
Yes. Take a picture of your website, upload that, and people won’t be able to copy the code of it.
In all seriousness, no. The browser has to be able to read all the output code in order to render your webpage, which means the browser must have the output code, which means anyone can access the output code.
The idea of putting out a public website is that it is publicly available.
No, you can’t stop someone from copying the HTML/CSS you send to the browser. One alternative is to make your pages as PDF pages, then they can’t copy HTML/CSS. This is not a good way to go about it, however.