Use script tag to include web3.js in any html:
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>
Following code snippet will check for any injected web3.js instance(Metamask etc). if not then will fallback to local geth node or infura endpoints.
function initweb3 () {
if(type of web3 !== 'undefined') {
// Use injected web3
web3js = new Web3(web3.currentProvider);
} else {
/* Fallback to local node or remote node
by default local HTTP-RPC server exposes port 8545.
you can use Infura Node Urls also
'https://ropsten.infura.io/<API KEy>'*/
web3js = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545'));
}
}
// You should initialize web3 instance after window load event has fired to avoid any race condition.
window.addEventListener('load',initweb3);