How to see an HTML page on Github as a normal rendered HTML page to see preview in browser, without downloading?
Asked Answered
S

11

530

On http://github.com developer keep the HTML, CSS, JavaScript and images files of the project. How can I see the HTML output in browser?

For example this: https://github.com/necolas/css3-social-signin-buttons/blob/master/index.html

When I open this it doesn't show the rendered HTML of the code of author. It shows the page as a source code.

Is it possible to see it as rendered HTML directly? Otherwise I always need to download the whole ZIP just to see the result.

Selfabuse answered 9/12, 2011 at 13:34 Comment(3)
similar question: Can I run HTML files directly from GitHub, instead of just viewing their source?Erleena
as of June 2019, raw.githack.com seems to be the most convenient solution (see answers to question linked above)Predacious
This is a really old thread but the fact that this isn't immediately obvious and easy to solve on github's site is insane.Jonme
L
652

New fork because the old project is abandoned;
The URLs are now (htmlpreview -> html-preview):


previously:

The most comfortable way to preview HTML files on GitHub is to go to https://htmlpreview.github.io/ or just prepend it to the original URL, i.e.: https://htmlpreview.github.io/?https://github.com/bartaz/impress.js/blob/master/index.html

Lanie answered 2/9, 2012 at 5:37 Comment(24)
@Denis: Which browser and which URL are you using? For now, it supports only Webkit and Gecko browsers.Lanie
@Denis: Sorry, Firefox 3.6 is too old to be supported. That said, you can open Firebug any try to debug it, if you are determined.Lanie
Any idea how to do this on a private repo? I don't want to paste my private URL w/ token into that tool. its a sweet tool tho.Ophicleide
@rynop: HTMLPreview is open source and it doesn't save any history, so nobody will know if you paste your private URL (except Github and Yahoo).Lanie
Prepending htmlpreview produces an error 404 There isn't a GitHub Page here.Hyperesthesia
@mangledorf, my bad, should prepend http://htmlpreview.github.com/? not just htmlpreview.Hyperesthesia
Note that this only works for public repos. Private ones will give the error message Error: Cannot load fileKostival
htmlpreview.github.com partly fails at rendering JavaScript and CSS. The alternative rawgit.com works better, serving files with proper Content-Type headers.Benner
@JulienCarsique But RawGit is a third-party proxy and can disappear one day, unlike github.com. Which URL doesn't work properly?Lanie
@Lanie htmlpreview.github.io/?https://github.com/nuxeo/nuxeo.github.io/…Benner
http://htmlpreview.github.io/?https://github.com/Startouf/IBDV/blob/master/Site/index.html Will not show my WebGL animation !Clover
@JulienCarsique, Cyril DD: The problem is due to the 'Access-Control-Allow-Origin' header in the AJAX response, which is blocked by browsers. Sorry I cannot do much with it.Lanie
This site doesn't work well with different encodings. Loading a windows-1250 page, properly stated in <head>, leads to wrong encoding.Swordbill
Hello, is there any similar tools for displaying markdown file ?Greeting
Great solution, thank you! I added the links to my R Notebooks with the prefix to the README.md file and it renders my nb.html file very well. Here is the page in case anybody wants to see how it works: github.com/sargdavid/snippets.cvi and htmlpreview.github.io/?https://github.com/sargdavid/…Matlick
@Shane, it now works with Github Enterprise :-) Simply enable it in your repo's Settings under the 'GitHub Pages' settings. Then, the settings page will give you the relevant link. (Apparently, it's usually simply putting pages. in front of the url. But don't worry, the config page will give you the correct url after you have enabled itGipps
your example htmlpreview.github.io/?https://github.com/bartaz/impress.js/… doesn't work htmlpreview.min.js:1 A parser-blocking, cross site (i.e. different eTLD+1) script. See chromestatus.com/feature/5718547946799104 for more details.Terrellterrena
Looks like this solution stops works at last days of December 2018 until now however we still have this https://mcmap.net/q/73672/-how-to-see-an-html-page-on-github-as-a-normal-rendered-html-page-to-see-preview-in-browser-without-downloadingMadlynmadman
it's a shame there isn't a renderer/view button, but then I realise you couldn't have a view button for every type that exists (but it would still be nice though)Godspeed
Couldn't it be useful to update the provided links with https (secure) protocol instead of http? I just realized I kept missing the obvious over a past couple of links, but it might be just the uniquely dark copy-paste monster in me doing things :)Angelia
If you use this service and have problems with React's react-router-dom - just try to use <HashRouter>.Cot
You're relying on an external website to solve the the problem that your browser isn't turning perfectly good HTML into a render. Phooey.Overtop
404 cant find my repo is privateWystand
For a private repo, you can get the URL of the raw HTML page with a token (when you click Raw on the file). By using this URL in htmlpreview.github.io, I am able to render a private HTML page. This method loads the page HTML page but does not load the dependencies properly.Feldt
P
118

If you don't want to download an archive you can use GitHub Pages to render this.

  1. Fork the repository to your account.
  2. Clone it locally on your machine
  3. Create a gh-pages branch (if one already exists, remove it and create a new one based off master).
  4. Push the branch back to GitHub.
  5. View the pages at http://username.github.io/repo`

In code:

git clone [email protected]:username/repo.git
cd repo
git branch gh-pages
# Might need to do this first: git branch -D gh-pages
git push -u origin gh-pages # Push the new branch back to github
Go to http://username.github.io/repo
Paulin answered 9/12, 2011 at 13:48 Comment(5)
I have forked a project now how i can copied it to github pages.Selfabuse
Updated my answer with a process.Paulin
It's well documented here help.github.com/articles/creating-project-pages-manuallyOrit
Why first create a master and clone it ("play it safe" in creating-project-pages-manually) ? Can one not checkout --orphan gh-pages only, push that, without messing with master at all ?Husband
You can also select the branch to publish in your repository settings, in the first tab (Options) near the bottom. It default to gh_pahes if the branch exists, else None (disabled). You can select master or any other branch.Unifoliate
B
71

🚩 Message from RawGit's creator and owner on https://rawgit.com:

RawGit has reached the end of its useful life October 8, 2018 RawGit is now in a sunset phase and will soon shut down. It's been a fun five years, but all things must end.

GitHub repositories that served content through RawGit within the last month will continue to be served until at least October of 2019. URLs for other repositories are no longer being served.

If you're currently using RawGit, please stop using it as soon as you can.

When I tried to use it, I got:

403 Forbidden

RawGit will soon shut down and is no longer serving new repos. >> Please visit https://rawgit.com for more details.

You can use RawGit:
https://rawgit.com/necolas/css3-social-signin-buttons/master/index.html

It works better (at the time of this writing) than http://htmlpreview.github.com/, serving files with proper Content-Type headers. Additionally, it also provides CDN URL for use in production.

Benner answered 16/1, 2015 at 15:8 Comment(8)
I confirm that it works better than htmlpreview. At least, it's showing my WebGL animations.Clover
It works faster actually, and with Bokeh (e.g.), it shows some of the interactions (e.g. tooltips) that don't work with htmlpreview.Gati
Like htmlpreview, doesn't work with private repositories. Git makes the URLs for these like public URLs by adding ?token=<hash>, but these tools should understand it and pass it to GH together with the rest.Brause
This is from the FAQ for rawgit: Can I use a rawgit.com development URL on a production website or in public example code? No. Only use rawgit.com URLs for low-traffic testing or for sharing temporary demos with a few people during development. Please use cdn.rawgit.com for anything that might result in heavy traffic or that people might copy and paste into their own code. ... There is more explanation availableHeartwhole
This one solved a problem I had with Github's html preview - some anchor links in my html page just didn't work there, while they work perfectly fine in Rawgit. thanks!Title
Can confirm: Rawgit will be shut down as of October 2019.Perren
raw.githack.com as an alternative for RawGit. More info: #62740862Gorrian
It seems RawGit has reached the end of its useful life.Mita
C
47

It's really easy to do with github pages, it's just a bit weird the first time you do it. Sorta like the first time you had to juggle 3 kittens while learning to knit. (OK, it's not all that bad)

You need a gh-pages branch:

Basically github.com looks for a gh-pages branch of the repository. It will serve all HTML pages it finds in here as normal HTML directly to the browser.

How do I get this gh-pages branch?

Easy. Just create a branch of your github repo called gh-pages. Specify --orphan when you create this branch, as you don't actually want to merge this branch back into your github branch, you just want a branch that contains your HTML resources.

$ git checkout --orphan gh-pages

What about all the other gunk in my repo, how does that fit in to it?

Nah, you can just go ahead and delete it. And it's safe to do now, because you've been paying attention and created an orphan branch which can't be merged back into your main branch and remove all your code.

I've created the branch, now what?

You need to push this branch up to github.com, so that their automation can kick in and start hosting these pages for you.

git push -u origin gh-pages

But.. My HTML is still not being served!

It takes a few minutes for github to index these branches and fire up the required infrastructure to serve up the content. Up to 10 minutes according to github.

The steps layed out by github.com

https://help.github.com/articles/creating-project-pages-manually

Connelly answered 9/2, 2014 at 9:13 Comment(3)
Works great. As a git noob, I forgot to $ git commit -m 'init' in between your lines.Preceptive
What will the URL be?Goldengoldenberg
hmm ... not so sure this is much easier than juggling kittens ...Cyperaceous
D
21

I read all the comments and thought that GitHub made it too difficult for normal user to create GitHub pages until I visited GitHub theme Page where its clearly mentioned that there is a section of "GitHub Pages" under settings Page of the concerned repo where you can choose the option "use the master branch for GitHub Pages." and voilà!!...checkout that particular repo on https://username.github.io/reponame

screenshot to support my answer

Doud answered 16/6, 2018 at 15:48 Comment(1)
This now appears to be a paid product only if you are using a private repo. It's available for public repos.Embrue
P
6

I have found another way:

  1. Click on the "Raw" button if you haven't already
  2. Ctrl+A, Ctrl+C
  3. Open "Developer Tools" with F12
  4. In the "Inspector" right-click on the tag and choose "Edit HTML"
  5. Ctrl+A, Ctrl+V
  6. Ctr+Return

Tested on Firefox but it should work in other browsers too

Printing answered 16/11, 2020 at 23:1 Comment(2)
Very good; a proper technical solution which solves the real problem without any monkey business of relying on external websites. This should be something in the File menu of your browser: "eval page text as HTML".Overtop
IMHO, it would be faster to save the raw html page anywhere and to open it with a browser (just press Downloaded files button).Vedetta
O
4

Also, if you use Tampermonkey, you can add a script that will add preview with http://htmlpreview.github.com/ button into actions menu beside 'raw', 'blame' and 'history' buttons.

Script like this one: https://gist.github.com/vanyakosmos/83ba165b288af32cf85e2cac8f02ce6d

Operculum answered 15/8, 2017 at 19:58 Comment(0)
A
4

Two approaches (for public repositories) worked well for me: both VERY SIMPLE and ABLE TO RENDER COMPLEX HTML PAGES with links to local CSS files and local JAVASCRIPT/VUE files.

  • METHOD 1 - With GitHub pages

To set up, go to: https://github.com/YOUR_ACCT_NAME/YOUR_REPO_NAME/settings/pages (see screen shot below)

enter image description here

Example of my original HTML page on the repo: https://github.com/BrainAnnex/life123/blob/main/experiments/life_1D/diffusion/diffusion_1.htm

How it looks rendered: https://brainannex.github.io/life123/experiments/life_1D/diffusion/diffusion_1.htm Notice how all the styling, graphics and interactive controls are all good :)

  • METHOD 2 - With free service raw.githack.com

Go to https://raw.githack.com/ and enter the full URL of yourpage (including the "/blob" part); e.g. https://github.com/BrainAnnex/life123/blob/main/experiments/life_1D/diffusion/diffusion_1.htm

Then the site generates 2 links that work quite well :)

A good alternative if GitHub pages were to become unavailable!

Achaea answered 16/6, 2022 at 6:54 Comment(0)
D
3

If you have configured GitHub Pages you can get your public url like as:

https://<username>.github.io/<repository>/index.html

where <username> & <repository> will be the placeholder for username & repo name respectively

So, the result will be like this: http://necolas.github.io/css3-social-signin-buttons/index.html

If it is an organization with GithubPages enabled in all the repositories it will be something like:

https://<org>.github.io/<repository>/
Dap answered 7/4, 2021 at 20:1 Comment(2)
What if the repo is in an organisation?Decalescence
@Decalescence it will be like https://<org>.github.io/<repository>/ i have updated the answerDap
C
1

If you are using an enterprise Github, you might not want to have a public facing github pages. One thing that worked for us is to:

For a HTML file in: https://github.private-repo.com/team/project/blob/master/order.html

Following is the URL that opens in a browser and retrieves the latest file as HTML: https://github.private-repo.com/pages/team/project/order.html

Cambist answered 13/1, 2023 at 19:29 Comment(1)
If you're using Enterprise GitHub then I think you can create a private GitHub Page.Crescint
O
0

This isn't a direct answer, but I think it is a pretty sweet alternative.

http://www.s3auth.com/

It allows you to host your pages behind basic auth. Great for things like api docs in your private github repo. just ad a s3 put as part of your api build.

Ophicleide answered 23/9, 2012 at 1:40 Comment(1)
Looks like a 3rd party service which has nothing common with git. Where is the instruction how to use it in context of this question?Messenger

© 2022 - 2024 — McMap. All rights reserved.